LoadRunner web_reg_find function - How to verify web page content?

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:
  1. Using LoadRunner content verification with web_reg_find function
  2. 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 of web_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?

  1. 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:

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

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

  2. Description of web_reg_find function attributes
    The simplest web_reg_find function can look like:

    1. 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

    Please, see a server response:
    The following web_reg_find function checks that server's name is 'Xitami':

    1. 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):

    1. int nFound;

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

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

    5. nFound = atoi(lr_eval_string("{TextPresent_Count}"));
    6. if (nFound == 11)
    7.     lr_output_message("Correct number of 'Coach class ticket' text: %d", nFound);
    8. else
    9. {
    10.     lr_error_message("Incorrect number of 'Coach class ticket' text: %d", nFound);
    11.     return 0;
    12. }

    If you have additional info on 8th line:

    1. 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 does not 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

    1. 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.

    use this approach to verify that your application work correctly under heavy load.

  3. '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.

  4. Other important info on web_reg_find function
    I understand, that the present article is not comprehensive :)

    So, what to read next?
    • Function Reference on web_reg_find function
      I didn't explain several features - text flags (light LoadRunner regular expressions), TextPfx/TextSfx attributes and so on.
    • Function Reference on web_find function
    • HP Knowledge base
Thank you, my readers.
Dmitry Motevich

Related articles:


SHAIL said...

hi..v.nice article..thanks..

SHAIL said...

can u pls explain me some use ful commonly used functions in realtime...while doing correlation other then web-reg_save_param any other functions will use...pls explain me in detail..thanks in advance

Dmitry Motevich said...

Which functions do you mean?

Anonymous said...

Hi Dmitry,
Is it possible to control the flow of script execution using web_reg_find? I feel you missed it to explain.

Dmitry Motevich said...

Actually, it depends on what do you mean with "to control the flow of script execution".

web_reg_find can help you to find an error. So, you should decide what to do with that error.
Something like this pseudo-code:

if (web_reg_find has found an error)
then to do smth
else to continue test

Anonymous said...

Hi Dmitry,

I created an script with load runner. I executed the script with 4 users, it was working, as I executed it with 5 users I got an error "Web_reg_find" is not found.

If i increase think time it works without any error.
It also works if we comment line with "Web_reg_find" function in script.
What is best solution?

Thanks in advance.

Dmitry Motevich said...

The best solution for what?

Richa said...


Could you pls explain how to use the web_image_check function like you have explained web_reg_find.

Dmitry Motevich said...

Dear Readers!
Thank you very much for you comments!

Since this article was published more than one year ago, I've just disabled an adding of new comments for the article.