Monday 30 June 2014

how to Capture a sub string or data from a string based on delimiters in Loadrunner

There is an inbuilt function in loadrunner that can be used to capture data from string by specifying delimiters. strtok function can be used to do the trick -

In below example it is shown that how all words can be captured from string "http://localhost/app/myapp:8080" by using 2 delimeters / and :

 extern char * strtok(char * string, const char * delimiters ); // Explicit declaration

    char String_org[] = "http://localhost/app/myapp:8080"; // original string 
    char delimiter[] = "/:";
    char * token;
    token = (char *)strtok(String_org, delimiter); // capture 1st sub string based on defined delimiter
    if (!token) {
        lr_output_message ("No tokens found in string!");
        return( -1 );
    }
    while (token != NULL ) { // While valid tokens are returned
        lr_output_message ("%s", token );
        token = (char *)strtok(NULL, delimiter); // Get the next token
    } 

Output: 
Starting iteration 1.
Starting action Action.
Action.c(15): http
Action.c(15): localhost
Action.c(15): app
Action.c(15): myapp
Action.c(15): 8080
Ending action Action.

What is the difference between Socket level data and Wininet level data in Loadrunner recording options

The 2 capture levels available in the recording options in loadrunner - socket level data and wininet level data, specifies the tool, where to hook and capture the communication packets from.

Most of the application though communicate at the socket level and the events get recorded by loadrunner using socket level data capture. But sometimes the applications are designed to interact using wininet API and in such cases we should use wininet level capture in loadrunner to capture the events successfully. So the use of socket level/wininet level capture depends on how the application communicates.

Note: The requests might get duplicated if you are using socket level and wininet level data capture and you can comment the duplicated requests in the script.



LoadRunner captured all events during recording but thrown an error during script generation - "Error during code generation. The Vuser script was not generated"

Sometimes the character sets used are not supported by LoadRunner (by default) and creates issue at the time of script generation. Try regenerating the script after enabling UTF-8 type supported charset in recording options as shown below :



HTTP Status-Code=401 (Unauthorized) error during script replay - HTTP/HTML protocol in Loadrunner





Try below options to rectify the error:


  • Option 1: Add web_set_user(username,password,host:port );
  • Option 2: Record the script after changing the capture level to Wininet level data in Recording option> Network > Port mapping > capture level
  • Option 3: Run the script after enabling Wininet replay instead of sockets option in Run time settings > Internet Protocol > Preferences> Advanced
  • Option 4 : If none of the above option works, record the business flow with fiddler and compare the requests in LoadRunner and fiddler. Identify if any request/header/cookie is missing in the load runner script and creating the issue.

Friday 27 June 2014

How to create and validate pdf File download script in LoadRunner

Saving a file to the local machine during recording a script in LoadRunner VUgen, by clicking on"save as" button, is a client side activity and does not get recorded.But the action on web page which results the file download box gets recorded in VUgen and actually downloads the file (pdf file/Zip file).
The downloaded file can be found in the data folder of recorded script by checking the size/type of contents.

To verify if the script is downloading file during run-time, check the iteration# folders (inside result1 folder) for the file.

If you know the size of file (in Kbs) which you are downloading, you can also use below code to check if the file has got downloaded successfully or not.


web_url (Request for file download)

DownloadSize = web_get_int_property( HTTP_INFO_DOWNLOAD_SIZE ); //define DownloadSize  as an integer variable at the beginning of action code

lr_output_message("Downloaded File size is %d" , DownloadSize);

if (DownloadSize < 1000) {  //The file to be downloaded has size of 1000 kbs


lr_error_message("File download has failed and downloaded content size in KBs is %d", DownloadSize);

}