How to Send Request with Cookie in nGrinder

Submitted by admin on 2014-07-11 14:33:08

Actually, there is a method in Grinder supporting send request with headers and Cookie is an item in the request header.

NVPair[] headers = new NVPair[1];
if(cookie!=null && cookie.trim().length()>0){
	headers[0] = new NVPair("Cookie", cookie);
}
HTTPResponse response = request.POST(uri, formData, headers);

 

How to POST a SOAP request with nGrinder/Grinder

Submitted by admin on 2014-07-11 09:32:24

Grinder is a very useful Web application performance testing tool (http://grinder.sourceforge.net/).

nGrinder utilize Grinder as it core and built a wonderful web UI for managing the users, scripts and tests (download nGrinder here).

Testing a Web Service is a common work so I hope the following codes will be helpful to you.

First, we need to specify proper header for the SOAP request and add to the request we want to send to the SOAP service:

def headers = [new NVPair("Content-Type", "text/xml; charset=utf-8"), new NVPair("Content-Length",  String.valueOf(soapMessage.length())  )] as NVPair[];
request.setHeaders(headers);

Then we convert the SOAP message to a byte array and send with "POST" method.

HTTPResponse result = request.POST( url, soapMessage.getBytes() );

Following is the full version of the code to perform SOAP service request.

def headers = [new NVPair("Content-Type", "text/xml; charset=utf-8"), new NVPair("Content-Length",  String.valueOf(soapMessage.length())  )] as NVPair[];
request.setHeaders(headers);
HTTPResponse result = request.POST( url, soapMessage.getBytes() );

 

Javascript - Conversion between ASC and String

Submitted by admin on 2014-07-01 14:01:51

In Javascript we often convert ASC to Char or Char to ASC.

Here shows you the useful functions for both of them:


<script>
function Asc(String)
{
	return String.charCodeAt(0);
}

function Chr(AsciiNum)
{
	return String.fromCharCode(AsciiNum)
}
</script>

 

How to run multiple tests concurrently in nGrinder?

Submitted by on 2014-07-01 13:56:50

I've been searching in google for a while for this topic and finally found this solution.

  1. Login nGrinder controller with user 1.
  2. Run script 1 with certain number of agents.
  3. Make sure that there are enough agents which are not reserved for the task of script 1.
  4. Login nGrinder controller with user 2.
  5. Run scrip 2 with certain number of agents which is equals to or less than the agents that are available.

Sounds easy, right?

How to Auto Accept Self Signed SSL Certificate with Selenium RC + Firefox

Submitted by on 2013-08-30 16:54:39

When a browser accesses a site with HTTPS which works with self signed certificate, we usually get an trust alert. This often happends if your company has a lot of development sites and don't purchase comercial certificate for cost control purpose.

Let me show you a very simple way to solve this problem.

See the following command which use to start your Selenium RC server:

java -jar selenium-server-standalone-2.33.0.jar -trustAllSSLCertificates -userExtensions user-extensions.js -maxSession 6 -role remotecontrol -hub http://localhost:4444/grid/register -nodeConfig nodeconfig.json

Pay attention to the string "-trustAllSSLCertificates", this is the matter.

In many other articles, they say you need to run with *firefoxproxy, but I found it can play well with *firefox.

Hope you enjoy it.

Java MySQL performance improved 10x by using executeBatch

Submitted by on 2013-08-13 15:22:49

Recently I've been loading some apache access logs into MySQL table for statistics. When I received the log files from my colleague, WOW, big files, the file size was over 9GB.

I immediately wrote some java code to accomplish this task but found that it was very slow by insert the records row by row, over 3 hours to complete the insertion.

Though I already did following tuning the performance is still bad:

  1. Delete index from this table before insertion
  2. Utilize connection pool
  3. Utilize multithreading (10 threads)


Since there will be more and more needs to load the access log, I have to resolve the performance issue.

At this point, I suddently recalled some code snippet with keyword "executeBatch" then I gave it a try and finally the performance improved 10x. It only cost about 15 minutes to complete inserting over 90 million rows. Let me show you the code:
 

    public static void batchInsert(String sql, List<object[]> params) throws Exception {
        Connection conn = MySQLConnection.getConnection(connStr);

        PreparedStatement stmt = conn.prepareStatement(sql);
        for (Object[] o : params) {
            for (int i = 0; i < o.length; i++) {
                stmt.setObject(i + 1, o[i]);
            }
            stmt.addBatch(); // run addBatch() for each SQL
        }

        stmt.executeBatch(); // start batch execute

        if (stmt != null) {
            stmt.close();
        }

        if (conn != null)
            conn.close();
    }


 

How to Have Wordpress Support Paste Images from Word

Submitted by ksblog on 2013-06-15 11:01:04

Sometimes we paste articles directly from Word which contains some images.

The images from Word will be converted to base64 Data URI in Wordpress editor like the following format:

<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAnAAAACpCAIAAAA......chgAAAABJRU5ErkJggg==" />

But in some previous version of Wordpress, it will always filter this kind of data which protocal is "data:" and causes the images pasted from Word couldn't be displayed correctly.

Now let's see how to make it work.

  1. Open file "wordpress\wp-includes\functions.php"
  2. Look for "static $protocols;"
  3. Add "data" as shown below, then restart apache and enjoy it.
function wp_allowed_protocols() {
	static $protocols;

	if ( empty( $protocols ) ) {
		$protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'data' );
		$protocols = apply_filters( 'kses_allowed_protocols', $protocols );
	}

	return $protocols;
}

 

Set or change the characters to upper case, lower case, capitalize with VBA in Excel.

Submitted by ksblog on 2012-07-13 14:23:26
  1. UPPER(a1): set a1 cell to be upper case.
  2. LOWER(a1): set a1 cell to be lower case.
  3. UPPER(LEFT(A1,1)) & LOWER(RIGHT(A1,LEN(A1)-1)): To capitalize the a1 cell, which means first letter with upper case and other letters with lower case.

WebDriver Download

Submitted by admin on 2011-11-15 22:58:56

The following URL is for downloading WebDriver libs:

http://code.google.com/p/selenium/downloads/list

Usually I download selenium-java-XX.jar.

You can download dotnet version: selenium-dotnet-XX.jar

The one with name "selenium-server-XX.jar" is the package with selenium RC.

You can see more information in that page.

WebDriver and Select

Submitted by admin on 2011-10-30 21:16:07

WebDriver provides simple and useful API for Select. With them you can easily deal with html Select with WebDriver. Please see the following sample code:

WebElement e = driver.findElements(By.id("select_id"));
Select select = new Select(e);
select.selectByValue("value"); // select by option value
select.selectByIndex(specific_index); // select by option index, start from "0"
select.selectByVisibleText("label_text"); // select by the visible option text

 

The above code show you how to select an option with WebDriver while the following is to deselect options:

// undo the selection for all options
select.deselectAll(); 

// undo selection by option index,  start from "0"
select.deselectByIndex(index);

// undo selection by option value of Select
select.deselectByValue("value");

// undo selection by option text of Select
select.deselectByVisibleText("text");

 

If you want to go through all options then this will help you a lot:

List options = select.getOptions();

 

Sometimes, you will operate on multi-selection Selects, below is also useful:

// check if the Select can be multiple selected
boolean isMultiple = select.isMultiple();

// return all the selected options
List selectedOptions = select.getAllSelectedOptions();

// only return the first one of all the selected options
WebElement option = select.getFirstSelectedOption();

 

WebDriver Select api makes your work efficient, right?