Showing posts with label http. Show all posts
Showing posts with label http. Show all posts

Monday, August 13, 2012

Recording Loadrunner Traffic in Fiddler

It can be useful to capture loadrunner http traffic in fiddler.  This can be useful, for example, for seeing the timeline of http requests, which ones are slow, what sort of parallelism exists, if any, etc.  It can also be useful to compare the vugen timeline of requests to the same information captured directly from the browser, as vugen may not match browser behavior as expected, by serializing what is sent asynchronously in parallel by the browser, etc.

Vugen can be configured in Runtime Settings, Internet Protocol, Proxy, Use Proxy Server, address=localhost, port=8888.
You then put breakpoints in the script before and after the section you want to record, run the script in vugen to the first breakpoint (with logging disabled), start capturing traffic in fiddler, run the script to the second breakpoint and stop capturing traffic in fiddler.  You can then see a visualization of the request pipeline in fiddler for your loadrunner traffic:
It is also a good idea to capture the traffic by running the script from the controller on the load generator to reduce vugen overhead.  You will get a more compact and realistic pipeline that way.

You can then record the same transaction manually using the web browser for comparison to loadrunner.



Monday, January 9, 2012

How to Test REST Web Service Using LoadRunner

A simple and easy method of load testing a REST service using LoadRunner is as follows:

  • use the http protocol
  • use web_custom_request
  • specify in web_custom_request the appropriate REST method: 
    • Method=PUT
    • Method=GET
    • Method=DELETE
The following script gives an example of this method in the case of REST PUT request using a JSON request message.  (XML request message would be similar).  One of the fields in the message is parameterized using a random number parameter.  The parameter is given a format of "0000000000000000000000%09lu" to achieve a 32 character-long number string.

Script

Action()
{
    char *request_json_base;
    char *request_json;


    // save web service url to param {URL}
    char *URL = "http://SERVER:8080/Path";
    lr_save_string(URL, "URL_Param");


    // save json request to param {REQUEST_JSON_PARAM}, parameterize "SomeID" as random number
    request_json_base=
     "{" 
     "    \"Field1\"       : \"ValueOfField1\"," 
     "    \"SomeID\"           : \"{SomeID}\","   
     "    \"Field2\"       : \"ValueOfField2\"," 
     "    \"Field3\"       : \"ValueOfField3\"," 
     "}";

    request_json = lr_eval_string(request_json_base);
    lr_save_string(request_json, "REQUEST_JSON_PARAM");
  
    // set http headers
    web_add_header("Content-Type", "application/json; charset=utf-8");


    // validate response
    web_reg_find("Text=success", LAST);


    // send JSON request
    lr_start_transaction("rest_put");


    web_custom_request("post_to_http_jms_provider",
    "URL={URL_Param}",
    "Method=PUT",
    "TargetFrame=",
    "Resource=0",
    "Referer=",
    "Mode=HTTP",
    "Body={REQUEST_JSON_PARAM}",
    LAST); 


    lr_end_transaction("rest_put", LR_AUTO);
}


Console Output

Action.c(49): Notify: Transaction "rest_put" started.
Action.c(51): Notify: Parameter Substitution: parameter "URL_Param" =  "http://SERVER:8080/Path"
Action.c(51): Notify: Parameter Substitution: parameter "REQUEST_JSON_PARAM" =  "{    "Field1"       : "ValueOfField1",    "SomeID"          : "00000000000000000000001244464508",    "Field2"       : "ValueOfField2",    "Field3"       : "ValueOfField3"}"
Action.c(51): t=258ms: 147-byte response headers for "http://SERVER:8080/Path" (RelFrameId=1, Internal ID=1)
Action.c(51):     HTTP/1.1 200 OK\r\n
Action.c(51):     Content-Type: application/octet-stream\r\n
Action.c(51):     Date: Mon, 09 Jan 2012 18:43:07 GMT\r\n
Action.c(51):     Content-Length: 7\r\n
Action.c(51):     \r\n
Action.c(51): t=271ms: 7-byte response body for "http://SERVER:8080/Path" (RelFrameId=1, Internal ID=1)
Action.c(51):     success
Action.c(51): Registered web_reg_find successful for "Text=success" (count=1)   [MsgId: MMSG-26364]
Action.c(51): web_custom_request("post_to_http_jms_provider") was successful, 7 body bytes, 147 header bytes   [MsgId: MMSG-26386]
Action.c(61): Notify: Transaction "rest_put" ended with "Pass" status (Duration: 0.1255 Wasted Time: 0.0000).