Sunday, 6 November 2016

Web_add_header And Web_add_auto_header Usage In Loadrunner

Web_add_header:

Web_add_header function is used to add header only to HTTP request that follows it.



Example:

web_add_header("Cookie""{Cookie_ID}");
web_add_header("Pragma""no-cache");

web_url("webmail",
    "URL=http://{URL}/etc/apps/webmail/",
    "Resource=0",
    "RecContentType=text/html",
    "Referer=",
    "Snapshot=t1.inf",
    "Mode=HTML",
    LAST);

web_add_header("Cookie""{Cookie_ID}");
web_add_header("Pragma""no-cache");

web_url("webmail_3",
    "URL=http://{URL}/etc/apps/webmail/?_task=mail&_action=getunread&_remote=1&_unlock=0&_={TimeStamp}",
    "Resource=0",
    "RecContentType=text/plain",
    "Referer=http://{URL}/etc/apps/webmail/?_task=mail",
    "Snapshot=t2.inf",
    "Mode=HTML",
    LAST);

web_add_auto_header:

Web_add_auto_header function is used to add header to all the consecutive HTTP requests.

Web scripts usually send the standard header requests automatically for each request. If you need additional headers to be sent then you can use web_add_header or web_add_auto_header.

web_add_header only sends to the HTTP request that follows it, whereas web_add_auto_header sends to all the succeeding requests.

Web_add_header and web_add_auto_header is automatically generated in your script, if you enable this in Record -> recording options->Advanced->Headers->Record Headers not in list.

Example:

web_add_auto_header("Cookie""{Cookie_ID}");
web_add_auto_header("Pragma""no-cache");

web_url("webmail",
    "URL=http://{URL}/etc/apps/webmail/",
    "Resource=0",
    "RecContentType=text/html",
    "Referer=",
    "Snapshot=t1.inf",
    "Mode=HTML",
    LAST);

web_url("webmail_3",
    "URL=http://{URL}/etc/apps/webmail/?_task=mail&_action=getunread&_remote=1&_unlock=0&_={TimeStamp}",
    "Resource=0",
    "RecContentType=text/plain",
    "Referer=http://{URL}/etc/apps/webmail/?_task=mail",
    "Snapshot=t3.inf",
    "Mode=HTML",
    LAST);

Difference Between HTML And URL Mode In Loadrunner

What is the difference between HTML and URL Mode?

HTML Mode:

HTML Mode is the default recording mode available in Loadrunner for Web (HTTP/HTML) scripts. When you record an application in HTML mode it will not record all the resources, but it will keep in extras as shown below and when the same script is executed it will parse all the urls one by one in extras and It will take some time to parse all the urls. Please find an example of HTML Mode below for Bing.com.

Bing.com in HTML Mode:

web_url("www.bing.com",
        "URL=http://www.bing.com/",
        "Resource=0",
        "RecContentType=text/html",
        "Referer=",
        "Snapshot=t1.inf",
        "Mode=HTML",
        EXTRARES,
        "Url=/s/a/bing_p_lg.ico""Referer="ENDITEM,
        "Url=/sa/8_01_1_3345848/notifications.js"ENDITEM,
        "Url=/sa/8_01_1_3345848/homepageImgViewer_c.js"ENDITEM,
        "Url=/fd/sa/9_00_0_3325577/rmsloaderdelayed.js"ENDITEM,
        "Url=/rms/AutoSugBlue/jc/f209ebd2/5c8aa5b3.js?bu=rms+answers+AutoSuggest+Modules%24Service.source%2cApi.source%2cDataProviders%24GenericDataProvider.source%2cAutoSuggestCanvas_r.source%2cAutoSuggestLayoutBlue_r.source%2cAutoSuggestSearchForm_r.source%2cAutoSuggestSpelling_r.source%2cAutoSuggestHighConfGhosting_r.source%2cAutoSuggestInit_r.source"ENDITEM,
        "Url=/s/as/8_01_1_3345848/Identity/WindowsLiveConnect_c.js"ENDITEM,
        LAST);

URL Mode:

In URL mode each and every resource is recorded explicitly. For example, when you look into a bing.com it will have images, css files, etc. The vugen will create a new web function for every resource separately and this leads to lot of code in your script and complex correlations. We use URL mode when we need  a better control over the resources of which files need to be downloaded or not. We can comment the script accordingly.

When you look into the same script in URL Mode it will create lots of steps as shown below for Bing.com

Bing.com in URL Mode:

web_url("www.bing.com",
        "URL=http://www.bing.com/",
        "Resource=0",
        "RecContentType=text/html",
        "Referer=",
        "Snapshot=t1.inf",
        "Mode=HTTP",
        LAST);

    web_concurrent_start(NULL);

    web_url("bing_p_lg.ico",
        "URL=http://www.bing.com/s/a/bing_p_lg.ico",
        "Resource=1",
        "RecContentType=image/x-icon",
        "Referer=",
        "Snapshot=t2.inf",
        LAST);

    web_url("notifications.js",
        "URL=http://www.bing.com/sa/8_01_1_3345848/notifications.js",
        "Resource=1",
        "RecContentType=application/x-javascript",
        "Referer=http://www.bing.com/",
        "Snapshot=t3.inf",
        LAST);

    web_url("homepageImgViewer_c.js",
        "URL=http://www.bing.com/sa/8_01_1_3345848/homepageImgViewer_c.js",
        "Resource=1",
        "RecContentType=application/x-javascript",
        "Referer=http://www.bing.com/",
        "Snapshot=t4.inf",
        LAST);

    web_url("rmsloaderdelayed.js",
        "URL=http://www.bing.com/fd/sa/9_00_0_3325577/rmsloaderdelayed.js",
        "Resource=1",
        "RecContentType=application/x-javascript",
        "Referer=http://www.bing.com/",
        "Snapshot=t5.inf",
        LAST);

    web_url("5c8aa5b3.js",
        "URL=http://www.bing.com/rms/AutoSugBlue/jc/f209ebd2/5c8aa5b3.js?bu=rms+answers+AutoSuggest+Modules%24Service.source%2cApi.source%2cDataProviders%24GenericDataProvider.source%2cAutoSuggestCanvas_r.source%2cAutoSuggestLayoutBlue_r.source%2cAutoSuggestSearchForm_r.source%2cAutoSuggestSpelling_r.source%2cAutoSuggestHighConfGhosting_r.source%2cAutoSuggestInit_r.source",
        "Resource=1",
        "RecContentType=application/x-javascript",
        "Referer=http://www.bing.com/",
        "Snapshot=t6.inf",
        LAST);

    web_url("WindowsLiveConnect_c.js",
        "URL=http://www.bing.com/s/as/8_01_1_3345848/Identity/WindowsLiveConnect_c.js",
        "Resource=1",
        "RecContentType=application/x-javascript",
        "Referer=http://www.bing.com/",
        "Snapshot=t7.inf",
        LAST);

Flex Protocol In Loadrunner - Recording

Overview of Flex Protocol:

What is Flex:
Flex emulates a client and server application method. Flex uses different technologies to develop Rich Internet Applications using Flash Player. Adobe Flex is a powerful framework, using we can develop powerful interactive applications. These flex applications are set of MXML and some other files combinely play the script on the flash player or also called swf files.

Examples: Share market graphs, that change dynamically over the internet. Usually, these type of applications are developed using Adobe Flex.


Recording: We usually record this application with multi protocol web and flex protocol. 


Correlation in Flex Protocol: For regular web functions we use the web_reg_save_param function for correlation. For flex we use lr_xml_get_values and lr_xml_find functions to capture the values from the response. The name itself indicates that we are capturing xml values from the response.


The main value which we do correlation in Flex protocol is DSID.

Once you record the script in Flex protocol search for the DSID in the script, the one which comes first is where the dynamic DSID value generated. Sometimes the script generates DSID multiple times. So, we need be careful while doing correlation.

We need to use lr_xml_get_value function to correlate this value. If you are new to this function, go to response of that request and go through the xml path and find the DSID value in XML path, right click and click on save parameter. It will automatically create lr_xml_get_values.

A typical DSID value looks like this "8129988E-DC65-8CF6-B808-98760876GE98".

Please find the attached screenshot for your reference.


Jar Files in Flex Protocol: You need to use some common jar files for flex protocol in Loadrunner 11.4 and earlier versions. From Loadrunner 11.5 there is no need to use jars. The common jars are.

Flex-messaging-core. jar

Flex-messaging-common. jar
Flex-messaging-opt. jar
Flex-messaging-proxy. jar
Flex-messaging-remoting. jar

Make sure to map the jars in the correct path and upload in the controller. If you do changes to the path make sure they are updated in your run time settings as well. You can also update the jar paths in.usr file in vugen.


Issues and how to fix them: The Java version plays a vital role during the scripting part. Make sure you use the same Java version for all your scripting part and the execution part. If we use different Java version the xml paths will change, validation and the correlations will fail.


How to set Java path and Jars: You can set your Java path and jars in runtime settings of the script.

Use of Lr_continue on error()function


By Using  lr_continue_on_error:

By using lr_continue_on_error function we can include a portion of the script instead of whole script. We need to enclose the requests that we are getting error in between lr_continue_on_error(1) and lr_continue_on_error(0)

lr_continue_on_error(1); web_url("Google", "URL=http://www.google.com/", "TargetFrame=", "TargetBrowser=Google ", "Resource=0", "RecContentType=text/html", "Snapshot=t1.inf", "Mode=HTML", LAST ); lr_continue_on_error(0);