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

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

    Tip:
    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:

LoadRunner tutorials

LoadRunner parameters:

LoadRunner correlation:

Recording:

LoadRunner Controller:


LoadRunner Analysis:

LoadRunner & QTP integration:

Content verification:

Monitoring:

LoadRunner coding/scripting:

LoadRunner unique file names:

Others:


Do you like these LoadRunner visual tutorials? Would you like to receive them in the future?
If yes, please subscribe to this blog RSS feed or by Email. (How to subscribe? Video guide)



Do you
know that you are free to use/copy/publish all my materials on your site/blog?


QTP Video & Text Tutorials

QTP Videos:

QTP DP (Descriptive Programming):

QTP & Excel:

QTP & XML:

QTP & PDF:


QTP & Browser:


QTP Scripts:


QTP & VBScript:

QTP & LoadRunner:

QTP Helps:

Others:



Do you like these QTP visual tutorials? Would you like to receive them in the future?
If yes, please subscribe to this blog RSS feed or by Email. (How to subscribe? VIDEO guide)



Do you know that you are free to use/copy/publish all my materials on your site/blog?