Archive

Archive for November, 2009

My blog posts in Chinese language

November 21st, 2009

Hi All

Thanks to Zee Gao (高楼) some of my posts are now translated into Chinese language on 7dtest.com forum. Here are the links:

Web Services performance using LoadRunner HTTP Vuser script – http://www.7dtest.com/bbs/thread-3483-1-1.html

Don’t waste your time – http://www.7dtest.com/bbs/thread-3481-1-1.html

Cleaning browser cache – http://www.7dtest.com/bbs/thread-3482-1-1.html

HTTP POST or GET – http://www.7dtest.com/bbs/thread-3480-1-1.html

Thanks Zee & 7dtest.com users!

Uncategorized

Automating web flow with Selenium and Eclipse IDE

November 21st, 2009

Some of you may already know Selenium. Basically it’s free and open source tool for web application functional testing. It’s mainly know as replacement for HP’s QuickTestProfessional. I’ve recently discovered Selenium as very helpful for automating data setup for load testing.

Here is a small description howto setup Eclipse and run Selenium script through it.

1) Download Eclipse IDE from http://www.eclipse.org/downloads/
2) Download Selenium RC from http://seleniumhq.org/download/
3) Download Junit from http://www.junit.org/
4) Create new project in Eclipse:

  • Go to File -> New -> Java Project
  • enter project name e.g. “Sample”
  • Click “Finish” button

5) Import Selenium and JUnit packages into the project:

  • In Package Explorer right click project “Sample” and select Properties
  • Go to “Java Build Path” then select “Libraries” tab
  • Click “Add External JARs” and import junit-4.7.jar and selenium-java-client-driver.jar

Now our Eclipse environment should be ready. Next step is to prepare a test case in Selenium IDE. I’ve prepared small test that searches for “linux” word in google. To export test case as Java, in Selenium IDE go to Options -> Format -> Java (Junit) Selenium RC. As a result you should get something like this:

  1. package com.example.tests;
  2.  
  3. import com.thoughtworks.selenium.*;
  4. import java.util.regex.Pattern;
  5.  
  6. public class Untitled extends SeleneseTestCase {
  7.         public void setUp() throws Exception {
  8.                 setUp("http://change-this-to-the-site-you-are-testing/", "*chrome");
  9.         }
  10.         public void testUntitled() throws Exception {
  11.                 selenium.open("/");
  12.                 selenium.type("q", "linux");
  13.                 selenium.click("btnG");
  14.         }
  15. }

Default Junit code generated by Selenium doesn’t use Selenium RC. Because of that I updated the code a little bit to connect to localhost Selenium RC on port 4444. Here is updated version:

  1. package com.example.tests;
  2.  
  3. import com.thoughtworks.selenium.*;
  4. import java.util.regex.Pattern;
  5.  
  6. public class Untitled extends SeleneseTestCase {
  7.         public DefaultSelenium selenium;
  8.         public void setUp() throws Exception {
  9.                 selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com/");
  10.                 selenium.start();
  11.         }
  12.         public void testUntitled() throws Exception {
  13.                 selenium.open("/");
  14.                 selenium.type("q", "linux");
  15.                 selenium.click("btnG");
  16.         }
  17. }

Now, lets add it in our Eclipse project:

  • In Package Explorer right click on our “Sample” project and select New -> Class
  • Enter class name “Untitled” and package name “com.example.tests”
  • Click “Finish” button

Before we run our test, we need to start Selenium RC. For that open command line and under selenium-remote-control-1.0.1/selenium-server-1.0.1 run command “java -jar selenium-server.jar”. It will run Selenium RC server on default port 4444.

Now, to start the test just select Run -> Run As -> Junit test. It should open two IE browsers. One for Selenium RC and second with Google results for “linux” word.

Because we run Java code, it’s only up to us how we want to run the test. Below is our example update to search for “linux” word in a loop 5 times with 5 seconds intervals.

  1. package com.example.tests;
  2.  
  3. import com.thoughtworks.selenium.*;
  4. import java.util.regex.Pattern;
  5.  
  6. public class Untitled extends SeleneseTestCase {
  7.         public DefaultSelenium selenium;
  8.         public void setUp() throws Exception {
  9.                 selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com/");
  10.                 selenium.start();
  11.         }
  12.         public void testUntitled() throws Exception {
  13.                 for(int i = 0; i < 5; i++)
  14.                 {
  15.                         selenium.open("/");
  16.                         selenium.type("q", "linux");
  17.                         selenium.click("btnG");
  18.                         selenium.waitForPageToLoad("10000");
  19.                         Thread.sleep(5000);
  20.                 }
  21.                
  22.         }
  23. }

General ,

Average transaction response time vs Granularity

November 7th, 2009

Correct me if I’m from but I always thought that for particular transaction there should be only ONE average response time. But it looks like it’s not the case in LR Analysis.

I recently discovered that by changing granularity on average transaction response time graph, Analysis also recalculates average times under the graph. In my understanding granularity is responsible only for making the graph easier to read and thats all it should do. But by changing granularity we are also changing how many points LR actually counts which results in different average response times for different granularity.

So shame that this is not mentioned in the manual. Of course according to HP support it is mentioned there and this is a feature, not a bug :)

So my tip for today: be careful when looking at response times on average transaction response graph. Use “Summary” page if you want to omit any mistakes.

LoadRunner , ,

Exception ACCESS_VIOLATION

November 7th, 2009

Web (HTTP/HTML) scripts in LoadRunner are implemented using C programming language. And like always with C, you should remember about some basics. One of them is that few string handling function can return NULL value instead of correct pointer which will definitely lead to exception like the one below:

  1. Action.c(7): Error: C interpreter run time error: Action.c (7):  Error — memory violation : Exception ACCESS_VIOLATION received.

Basically if you see message like this, it is not any internal LoadRunner error. It means that you made a mistake in your script and you need to fix it. But let’s start from the beginning with some example:

  1. Action()
  2. {
  3.         char * x_p;
  4.        
  5.         lr_save_string("hello_world!", "MESSAGE");
  6.         x_p = (char *)strchr(lr_eval_string("{MESSAGE}"), ‘ ‘);
  7.         lr_save_string(x_p, "MESSAGE_FROM_SP");
  8.         lr_output_message(lr_eval_string("{MESSAGE_FROM_SP}"));
  9.        
  10.         return 0;
  11. }

This small piece of code takes parameter MESSAGE with value “hello_world”, then search for the first space character and display the string starting from that place up to the end. Function strchr() is responsible for searches for the space character. If it’s found then strchr() will return a valid pointer (something like 0xb36ac56e). But if the space is not there (which is our case since there is no space in the hello message), strchr() will return NULL which refers to 0×0 memory address location.

Such memory address is a very special address. Basically any read attempt from there is threated as incorrect operation and results in memory access violation (not only in LoadRunner).

Now, howto deal with it? If you see ACCESS_VIOLATION, in most cases it means that your LR script is working on incorrect/incomplete values. You are responsible for error handling in your scripts and you should always:

  • validate parameter’s values
  • check results of C functions to handle any errors, unexpected conditions
  • remember that you can’t always expect correct values and you need to handle it as well

Here is our example with fix showing howto deal with ACCESS_VIOLATION. We are calling strchr() function and checking if value returned is not NULL.

  1. Action()
  2. {
  3.         char * x_p;
  4.        
  5.         lr_save_string("hello_world!", "MESSAGE");
  6.         x_p = (char *)strchr(lr_eval_string("{MESSAGE}"), ‘ ‘);
  7.        
  8.         if(x_p) // if the pointer is not NULL display correct message
  9.         {
  10.                 lr_save_string(x_p, "MESSAGE_FROM_SP");
  11.                 lr_output_message(lr_eval_string("{MESSAGE_FROM_SP}"));
  12.         }
  13.         else //if pointer is NULL display error message
  14.         {
  15.                 lr_error_message("Space not found in MESSAGE parameter");
  16.         }
  17.         return 0;
  18. }

More details about NULL pointer here http://en.wikipedia.org/wiki/Pointer_(computing)#The_null_pointer

LoadRunner , ,