Sunday 9 June 2013

CHECK POINTS--LoadRunner web_reg_find function - How to verify web page content?

When you perform load testing, you have to be fully confident, that your application works correctly. It may be very usefull to check UI of application - is it shown correctly or not.

This verification can be performed with 2 ways:
Using LoadRunner content verification with web_reg_find function  Running LoadRunner GUI Vusers (QTP or WR scripts)
The present LoadRunner tutorial describes content verifications with web_reg_find function. I will explain and show a usage ofweb_reg_find function, its attributes and result.
To get additional information about the seconds approach (running LoadRunner GUI Vusers), please read the article How to execute QTP script from LoadRunner?
How to add LoadRunner content verification?Let's start with LoadRunner demo Web application - Web Tours.
I will show how to check that a greeting 'Welcome to the Web Tours site' is shown on a start page:

I've recorded a simple script on Web Tour application - it just opens a start page, logs in, and logs out:

After that:
open the script in Tree View (with menu 'View/Tree View')
select initial step ('Url: WebTours')
select the text I would like to check on the page and
right mouse click: Use default seetings in 'Find Text' dialog:

Then open your LoadRunner script in Script View (menu 'View/Script View') and you will see that web_reg_find function has been just added before the first function:

web_reg_find("Text=Welcome to the Web Tours site", "Search=Body", LAST);
web_url("WebTours", "URL=...", ...

Note:web_reg_find function has been added before the page opening function (web_url)!
This is because LoadRunner web_reg_find function does not search for text on a page, it just registers a search request for a text string on an HTML page.

This is very important and I would like to pay your attention - web_reg_find function should be placed before the function, which loads a page.
Description of web_reg_find function attributes
The simplest web_reg_find function can look like:

web_reg_find("Text=Welcome to the Web Tours site", LAST);
This form means 'register a request to search for a "Welcome to the Web Tours site" text on a next Web page retrieved from a server.

Attribute 'Text=' contains a text, that should be searched.
If the check fails, the error is reported after the next action function executes:

Attribute 'Search=' defines the scope of the search:
Body (default value) means to search in a body of server's response and its resources
Headers means to search within a pages headers
Noresource means to search in a body of HTML page retrived from server and do not searhc in its resources
Example:
Please, see a server response:
The following web_reg_find function checks that server's name is 'Xitami':

web_reg_find("Text=Server: Xitami", "Search=Headers", LAST);

The next important attribute of web_reg_find function is 'SaveCount='. Use it to save a number of matches that were found.

Let me show an example on this attribute and you will understand it.
Imagine, that we have to get a number of 'A Coach class ticket for :' text on Itinerary page:
The following code:
uses web_reg_find function with "SaveCount=" attribute (3rd line) before the Itinerary page loads
then loads Itinerary page (6th line)
extracts number of matches (8th line) and
compares it to an expected value (9th line):

int nFound;

web_reg_find("Text=A Coach class ticket for :", "SaveCount=TextPresent_Count", LAST);


// open Itinerary page
web_image("Itinerary Button", "Alt=Itinerary Button", LAST);


nFound = atoi(lr_eval_string("{TextPresent_Count}"));
if (nFound == 11)
lr_output_message("Correct number of 'Coach class ticket' text: %d", nFound);
else
{
lr_error_message("Incorrect number of 'Coach class ticket' text: %d", nFound);
return 0;
}

If you have additional info on 8th line:

nFound = atoi(lr_eval_string("{TextPresent_Count}")); please, read my article How to perform basic operations on LoadRunner parameters?

All previous examples generated errors when text was not present on a page. What about the case, when should check that a web page doesnot containa specific text, say 'Exception occurred'? For that we can use 'Fail=' attribute.

Possibles values:
NotFound (default value) means to generate error if the text is not found on a page
Found means to generate error if the text is found on a page
For example, the following web_reg_find function

web_reg_find("Text=Error occurred","Search=Body", "Fail=Found", LAST); will fail only if a web page contains "Error occurred" text.
If this text is not shown on a page, then function finishes successfully.

Tip: use this approach to verify that your application work correctly under heavy load.
'Find Text' dialog for web_reg_find function
You can generate all content verifications manually or with 'Find Text' dialog.
I would recommend using of 'Find Text' dialog for LoadRunner beginners.

For example, there is an analogous 'Find Text' dialog options for previous web_reg_find function example (with 'Error occurred'):

As for me, I prefer writing web_reg_find function and its attributes manually.
Other important info on web_reg_find function
I understand, that the present article is not comprehensive :)

No comments: