Archive

Posts Tagged ‘LoadRunner’

LoadRunner levels of integration with web pages

March 9th, 2010

LoadRunner basically allows two approches for load testing your web application. Before going into details lets see how communication between user and web server looks like.

As you can see between user and web server there are mainly 2 layers:

  • Layer 1 is where user interacts with the browser by e.g. clicking a button, selecting values from the list or submitting a form
  • Layer 2 is where browser communicates with web server which includes:
    • creating and sending HTTP requests to the web server based on user’s actions
    • receiving HTTP responses from the web server
    • rendering HTTP responses, forming an UI and displaying it to the user

Below I’m providing two scripts that do exactly the same thing but in slightly different way. The goal for each script is to search for a “linux” word using google search.

First, lets look at “Web (HTTP/HTML)” type of the script:

  1. Action()
  2. {
  3.         web_url("www.google.com",
  4.                 "URL=http://www.google.com/",
  5.                 "Resource=0",
  6.                 "RecContentType=text/html",
  7.                 "Referer=",
  8.                 "Snapshot=t1.inf",
  9.                 "Mode=HTML",
  10.                 LAST);
  11.  
  12.         lr_think_time(6);
  13.  
  14.         web_url("search",
  15.                 "URL=http://www.google.co.uk/search?hl=en&source=hp&q=linux&btnG=Google+Search&meta=&aq=f&oq=",
  16.                 "Resource=0",
  17.                 "RecContentType=text/html",
  18.                 "Referer=http://www.google.co.uk/",
  19.                 "Snapshot=t2.inf",
  20.                 "Mode=HTML",
  21.                 LAST);
  22.  
  23.         return 0;
  24. }

What happens here?

  • In line 3 we are entering google.com web site
  • In line 14 we are sending HTTP request that browser would generate after searching for value “linux”

Now, lets look at “Web (Click and Script)” type of the script:

  1. Action()
  2. {
  3.  
  4.         web_browser("www.google.com",
  5.                 DESCRIPTION,
  6.                 ACTION,
  7.                 "Navigate=http://www.google.com/",
  8.                 LAST);
  9.  
  10.         web_edit_field("q",
  11.                 "Snapshot=t1.inf",
  12.                 DESCRIPTION,
  13.                 "Type=text",
  14.                 "Name=q",
  15.                 ACTION,
  16.                 "SetValue=linux",
  17.                 LAST);
  18.  
  19.         web_button("INPUT",
  20.                 "Snapshot=t2.inf",
  21.                 DESCRIPTION,
  22.                 "Type=submit",
  23.                 "Tag=INPUT",
  24.                 "ID=",
  25.                 "Value=Google Search",
  26.                 ACTION,
  27.                 "UserAction=Click",
  28.                 LAST);
  29.  
  30.         return 0;
  31. }
  • In line 4 we are entering google.com web site
  • In line 10 we are typing value “linux” into the input field
  • In line 19 we are clicking “Google Search” button that will move us to the page with search results

So what is the difference between these two scripts?

First script operates on much lover level comparing to second script. It deals with HTTP requests without taking care about what actions user actually performs. It doesn’t care how fast user’s browser renders and display the UI. It only checks how fast web server is able to response with correct message.

Second script operates only on UI level without taking care what happens underneath. Response time here includes not only time needed to send/receive HTTP traffic but also time needed to form/display UI to the user.

Basically second script approach is less error prone because you don’t have to deal with low level things like HTTP parameters. And You are replicating user’s actions in a natural way.

So if you need to choose, then I would recommend Web Click and Script type of the script.

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 , ,

Validating Web Service response with XPath

May 18th, 2009

The easiest way for checking web service response in HP LoadRunner is by using XPath query language. LR API contains few functions designed especially for dealing with XML.

  1. lr_xml_get_values()  //Retrieves values of XML elements found by a query
  2. lr_xml_set_values()  //Sets the values of XML elements found by a query
  3. lr_xml_extract()  //Extracts XML string fragments from an XML string
  4. lr_xml_delete()  //Deletes fragments from an XML string
  5. lr_xml_replace()  //Replaces fragments of an XML string
  6. lr_xml_insert()  //Inserts a new XML fragment into an XML string
  7. lr_xml_find()  //Verifies that XML values are returned by a query
  8. lr_xml_transform()  //Applies Extensible Stylesheet Language (XSL) Transformation to XML data

Now, lets say we have sample web service for on-line book store and we want to ask what is the author for book id 123. Our web service can send following XML as a response:

  1. <books>
  2.   <book>
  3.       <id>123</id>
  4.       <author>John Smith</author>
  5.       <title>Working with Legacy code</title>
  6.       <publisher>Microsoft</publisher>
  7.   </book>
  8. </books>

For checking if the “author” element within XML response contains “John Smith” value we will use lr_xml_get_values() function. Here is the code that calls web service and checks if the value is as expected:

  1. Action()
  2. {
  3.      web_add_header("SOAPAction", "\"CallMe\"");
  4.      lr_start_transaction("AUTHOR");
  5.      soap_request("StepName=Sample Soap Request",
  6.        "ExpectedResponse=ANY",
  7.        "URL=http://foo.com/api",
  8.        "SOAPEnvelope= "
  9.        "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  10.        "<soap:Envelope "
  11.        "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" >"
  12.        "<soap:Body soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
  13.        "<GetBookDetails>"
  14.        "<idValue>123</idValue>"
  15.        "</GetBookDetails>"
  16.        "</soap:Body>"
  17.        "</soap:Envelope>",
  18.        "Snapshot=t765765765.inf",
  19.        "ResponseParam=Response_Xml",LAST);
  20.  
  21.  
  22.      lr_xml_get_values("XML={Response_Xml}",
  23.           "ValueParam=Author_Name",
  24.           "Query=/books/book/author",
  25.           LAST);
  26.  
  27.      lr_output_message(lr_eval_string("Author is = {Author_Name}"));
  28.  
  29.      if(strcmp(lr_eval_string("{Author_Name}"),"John Smith") == 0)
  30.      {
  31.         lr_end_transaction("AUTHOR", LR_PASS);
  32.      }
  33.      else
  34.      {
  35.         lr_end_transaction("AUTHOR", LR_FAIL);
  36.      }
  37.      return 0;
  38. }

First argument in lr_xml_get_values() call is parameter name that holds response XML. Second argument in name of new parameter that will hold author value extracted from response XML. Third argument is XPath query that extracts author element value.

LoadRunner , , ,

Running LoadRunner scenarios from QualityCenter automatically

February 25th, 2009

There is a very nice tool provided by HP Support that allows running few LoadRunner scenarios from QualityCenter using command line. You can use it to run load tests in regression every night for example.

Officially HP doesn’t support this small tool and they say it’s free and open source. There are two versions available. One for QC 9.0 and another for QC 8.2 SP1. If you want to find it on HP support page, just search for document ID KM191021.

cpt38343a – this is my local mirror for QC 9.0 version

LoadRunner ,

IBM WebSphere MQ testing using LoadRunner

February 23rd, 2009

My first script for WebSphere MQ testing was written in Java as Java Vuser script. It was pretty simple since I was using just MQ JMS API.  There is lots of examples howto connect to WebSphere in Java. Here is one http://hursleyonwmq.wordpress.com/2007/05/29/simplest-sample-applications-using-websphere-mq-jms/.

But howto test WebSphere MQ if you don’t have Java license in you LoadRunner?

There is a way to do that. LoadRunner API contains several JMS functions:

jms_receive_message_queue()
jms_send_message_queue()
jms_send_receive_message_queue()
jms_set_general_property()
jms_set_message_property()

First of all you need to have “Web Services” license to use them.

Here is what you need to do:

  • Get details of your environment like: MQ server IP, port (probably 1414), Queue Manager name, Queue name and channel name.
    Install IBM WebSphere MQ Client on machine where you have LoadRunner Controller (or LoadRunner Generator if you are using remote one). MQ Windows Client for WebSphere 6.0 can be downloaded here.
  • Setup details of our WebSphere MQ server on the client. We will use JNDI to store connection details (host, port, etc…)
  • Edit file C:\Program Files\IBM\WebSphere MQ\Java\bin\JMSAdmin.config and set

INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory
PROVIDER_URL=file:/C:/JNDI

  • Create new .scp file and put there your MQ server details. Here an example

DELETE QCF(QueueConnectionFactory)
DEFINE QCF(QueueConnectionFactory) QMGR(QUEUE_MANAGER) tran(client) chan(SYSTEM.ADMIN.SVRCONN) host(192.168.12.13) port(1414)
DISPLAY QCF(QueueConnectionFactory)
DEFINE Q(MY_QUEUE) QUEUE(MY_QUEUE) QMGR(QUEUE_MANAGER)
DISPLAY Q(MY_QUEUE)
end

  • Last step for MQ Client is to generate .bindings file (placed automatically in C:/JNDI) with JMSAdmin tool from C:\Program Files\IBM\WebSphere MQ\Java\bin directory. Assuming that your .scp file is named My_qm.scp, use this command:

JMSAdmin < My_qm.scp

Now in LoadRunner:

  • Create new Web Services script
  • Open Run-Time settings (F4) and go to JMS/Advanced
  • Change JNDI initial context factory to “com.sun.jndi.fscontext.RefFSContextFactory”
  • Change JNDI provider URL to “file:/C:/JNDI”
  • Change JMS connection factory to “QueueConnectionFactory” and click OK

Use this sample code to send and receive a message from IBM WebSphere MQ:

//setting JMS message property JmsMessageID
jms_set_message_property("JMSMessageID","JMSMessageID", "12345");

//sending message
jms_send_message_queue("Sending message","My cool message", "MY_QUEUE");

//receiving message
jms_receive_message_queue("Receiving message", "MY_QUEUE");

//displaying message
lr_message(lr_eval_string("{JMS_message}"));

Received message is saved in “JMS_message” parameter automatically by LoadRunner.

Done. Smart and simple :)

LoadRunner , , ,

How to crash LoadRunner 9.0 in 5 steps

January 15th, 2009

I’ve found it during playing with latest LR version. Steps to reproduce:

  • Open controller
  • Create new goal oriented scenario
  • edit goal type and select “Virtual Users” goal
  • set 0 (zero) as amount of Vusers to reach
  • click OK

Done. LR crashes without any error message, without completely anything. And I thought  boundary value testing is something basic… :/

P.S. This bug is already reported to HP.

LoadRunner , ,