Thursday 27 November 2014

Creating dynamic post parameters using Jmeter

If post data(Name - Value pair) of  a request changes dynamically, then you need to construct the same from the response of previous requests. To do that in jmeter add "Beanshell PreProcessor /JSR223 PrePocessor" as a child to the corresponding request and use following code.


sampler.addArgument("Name", "Value");


Eg:





Thursday 20 November 2014

Random Co-relation in Web http/html Load Runner

Use following LR function to extract all the elements from the response

web_reg_save_param_ex("ParamName=cseatPref",
                                         "LB=name=\"seatPref\" value=\"""RB=\"",
                                         "Ordinal=ALL"LAST);

lr_save_string(lr_paramarr_random("cseatPref"), "cSeatPref_Value");

//lr_paramarr_random() function selects a random value from all extracted values
//lr_save_string() function saves value to a new variable

Replace seat preference value with {cSeatPref_Value} as following

web_submit_data("reservations.pl",
        "Action=http://127.0.0.1:1080/cgi-bin/reservations.pl",
        "Method=POST",
        "TargetFrame=",
        "RecContentType=text/html",
        "Referer=http://127.0.0.1:1080/cgi-bin/reservations.pl?page=welcome",
        "Snapshot=t4.inf",
        "Mode=HTML",
        ITEMDATA,
        "Name=advanceDiscount", "Value=0", ENDITEM,
        "Name=depart", "Value={cDep_City}", ENDITEM,
        "Name=departDate", "Value={Dep_date}", ENDITEM,
        "Name=arrive", "Value={cAri_City}", ENDITEM,
        "Name=returnDate", "Value={Arri_date}", ENDITEM,
        "Name=numPassengers", "Value=1", ENDITEM, 

      "Name=seatPref", "Value={cSeatPref_Value}", ENDITEM,
      "Name=seatType", "Value={c_SeatType}", ENDITEM,      
        LAST);

Tuesday 18 November 2014

HTML vs. URL based scripting Load Runner

Load Runner has two types of recording options


  • HTML based scripting
  • URL based scripting

HTML:

  • It records/captures a user scenario similar to how a user interacts with an application, it can be called as browser context recording.
  • It will not send any explicit requests to static resources (.css, .js, .png...etc) or dependent requests, but downloads them automatically along with main request, unlike the URL based scripting
Script Type 1: A script describing user actions (eg: web_link, web_submit_form)

  • web_link, web_submit_form..etc are context sensitive functions and they depend on previous operations.
  • It works at HTML level(i.e DOM elements level)
     Eg:





As shown above web_image function("Search Flight Button") works only when the DOM elements (i.e <IMG> and its attributes) are loaded upon successful completion of previous operations.

Script Type 2: A script containing explicit URLs  only (eg: web_url, web_submit_data)
  • web_url, web_submit_data..etc are context less functions and they are independent of previous operations.
  • It works at HTTP level (i.e Request - Response based) 
     Eg: 

Observe that "search flight button" is recorded as web_url function, it sends an explicit request(i.e using URL attribute) when user clicks 'Flight' button, so it is independent of previous operations.

URL:


  • It will send explicit requests to static resources (.css, .js, .png...etc) and dependent requests along with main request.(refer below screenshot)
  • Its a context-less recording unlike the HTML based scripting.
  • It works at HTTP level (i.e Request - Response based).
Script Type 1: Create concurrent groups for resources after their HTML page

  • Records URLs and their resources in concurrent groups, a concurrent group represents links and resources that are loaded on a page at the same time.
      Eg: 



Observe that for a 'Search Flight Button' action, it records dependent and static resources requests       explicitly(web_concurrent requests) along with main request. (i.e all the web_concurrent group requests above belongs to "Search Flight Button" action).

Script Type 2: Use Web Custom Requests only


  • It records all requests as web_custom requests
  • The web_custom_request function is an action function that allows you to create a custom HTTP request using any method or body.
     Eg: 





Note: What kind of recording options to be selected depends on kind of application and how you want to emulate the scenario, but generally "HTML" with "Script Type 2: A script containing explicit URLs  only (eg: web_url, web_submit_data)" is preferred.