LoadRunner extract a string from within a string

When testing it is sometimes difficult to define suitable delimiters which allow you to correlate information for use later in a script. For example I once tested an application where code similar to this was returned. In the attached example I captured a large amount of returned data.

Sample HTML


In this example a large hexadecimal number identified the account. Due to the large number of quotation marks prior to the string that I was interested in and the fact that multiple strings were returned by the web page, it was difficult to capture the string directly. Instead I decided to capture the whole of the above text and then extract the HEX6A31013657A217B4A2254993C29633893A920BAE3C9400DB string from the captured text.

Using the C function strtok it is possible to extract data from a string based on delimiters. In this case I needed the fifth value in the string that is separated from the rest of the returned data by the [“] delimiter. I used a loop function to repeatedly search through the returned data until it reaches the fifth quotation mark.

 

Sample Loop

Then the captured “token” can be written to a string.

 

Save String


LoadRunner Error “Failed to connect to server” when opening vugen

After upgrading to LoadRunner 9.x I started getting a window popup which said “Failed to connect to server” every time I opened virtual user generator (vugen.exe).

The solution to this was to close virtual user generator and delete the [vugen.ini] file.
vugen.ini is found in the %systemroot% folder on your Windows PC (usually C:WINDOWS or C:WINNT).

Once you’ve deleted the file, virtual user generator will open without any issues and create a new vugen.ini file automatically.

How to select a random parameter from a captured list using LoadRunner

When performance testing it is important to simulate realistic user journeys through an application. With this in mind it might be necessary to choose options at random from a list. In the example below which was used to performance test a share dealing application it was necessary to simulate the purchase of different shares so that all vUsers aren’t selecting the same share.

The lr_paramarr_random function can be use to simulate users selecting different items from a dropdown list.
First capture the parameter using a web_reg_save_param function, select all ordinal values using ORD=ALL.
LoadRunner Screenshot

In the example above the following values were captured.
Action.c(118): Notify: Saving Parameter “CompanyName_1 = BARCLAYS ORD GBP0.25”
Action.c(118): Notify: Saving Parameter “CompanyName_2 = HBOS ORD GBP0.25”
Action.c(118): Notify: Saving Parameter “CompanyName_3 = LLOYDS TSB GROUP ORD GBP0.25”
Action.c(118): Notify: Saving Parameter “CompanyName_4 = TESCO ORD GBP0.05”
Action.c(118): Notify: Saving Parameter “CompanyName_5 = VODAFONE GROUP ORD USD0.11428571
The lr_save_string function is then used to save one of the “CompanyName” parameters into a new parameter called “RandCo”.

LoadRunner screenshot

e.g.
Action.c(154): Notify: Parameter Substitution: parameter “RandCo” =  “HBOS ORD GBP0.25