Friday, April 4, 2014

Web service Performance Testing using Load runner

This post explains about the performance test scripting for web service without recording.

we have various methods to test the web service performance testing in load runner it self , by using web service protocol.

More feasible way is by using web custom request , this would facilities more reliable scripting.

Taken  weather report as an example for load runner scripting  (Sample SOAP requests are available on below site).

http://www.webservicex.com/globalweather.asmx.

1) Choose Web(HTTP/HTML) protocol and Don't record , put the below simple code will serve the purpose.

Action()
{

   char *request_xml;



   // save web service url to param
    char *URL = "http://www.webservicex.com/globalweather.asmx";
    lr_save_string(URL, "URL_Param");


 // save xml request to param
 request_xml=
  "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
    "<soap:Body>"
     "<GetWeather xmlns=\"http://www.webserviceX.NET\">"
    "<CityName>Seattle</CityName>"
    "<CountryName>United States</CountryName>"
     "</GetWeather>"
    "</soap:Body>"
  "</soap:Envelope>";

 lr_save_string(request_xml, "REQUEST_XML_PARAM");

 // add http headers

 web_add_header("Host", "www.webservicex.com");


 web_add_header("Content-Type", "text/xml; charset=utf-8");


 web_add_header("SOAPAction", "http://www.webserviceX.NET/GetWeather");



         // validate response
 web_reg_find("Text=SEATTLE-TACOMA INTERNATIONAL  AIRPORT , WA, United States (KSEA)", LAST);

 //SEATTLE-TACOMA INTERNATIONAL AIRPORT , WA, United States
 //
 //
 // send request
 //

 lr_start_transaction("post_xml");

 //  This is to capture the Temperature of the "Seattle" City.


 web_reg_save_param("ResponseBody",
    "LB=Temperature",
    "RB=/Temperature",
    "Search=Body",
    "IgnoreRedirections=Yes",
    LAST);




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


  lr_output_message("Temp is<>: %s",lr_eval_string("{ResponseBody}"));





 lr_end_transaction("post_xml", LR_AUTO);
}


Out put of the script execution:

with extended log enabled on load runner script.

Virtual User Script started at : 2014-04-04 20:17:00
Starting action vuser_init.
Web Turbo Replay of LoadRunner 11.0.0 for Windows 7; build 8825 (Aug 15 2010 23:38:14)   [MsgId: MMSG-27143]
Run Mode: HTML   [MsgId: MMSG-26000]
Run-Time Settings file: "C:\Users\\AppData\Local\Temp\noname1\\default.cfg"   [MsgId: MMSG-27141]
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(10): Notify: Saving Parameter "URL_Param = http://www.webservicex.com/globalweather.asmx".
Action.c(25): Notify: Saving Parameter "REQUEST_XML_PARAM = <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetWeather xmlns="http://www.webserviceX.NET"><CityName>Seattle</CityName><CountryName>United States</CountryName></GetWeather></soap:Body></soap:Envelope>".
Action.c(29): Warning -26593: The header being added may cause unpredictable results when applied to all ensuing URLs. It is added anyway   [MsgId: MWAR-26593]
Action.c(29): web_add_header("Host") highest severity level was "warning"   [MsgId: MMSG-26391]
Action.c(32): Warning -26593: The header being added may cause unpredictable results when applied to all ensuing URLs. It is added anyway   [MsgId: MWAR-26593]
Action.c(32): web_add_header("Content-Type") highest severity level was "warning"   [MsgId: MMSG-26391]
Action.c(35): web_add_header("SOAPAction") was successful   [MsgId: MMSG-26392]
Action.c(40): Registering web_reg_find was successful   [MsgId: MMSG-26390]
Action.c(48): Notify: Transaction "post_xml" started.
Action.c(53): Registering web_reg_save_param was successful   [MsgId: MMSG-26390]
Action.c(63): Notify: Parameter Substitution: parameter "URL_Param" =  "http://www.webservicex.com/globalweather.asmx"
Action.c(63): Notify: Parameter Substitution: parameter "REQUEST_XML_PARAM" =  "<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetWeather xmlns="http://www.webserviceX.NET"><CityName>Seattle</CityName><CountryName>United States</CountryName></GetWeather></soap:Body></soap:Envelope>"
Action.c(63): t=763ms: 277-byte response headers for "http://www.webservicex.com/globalweather.asmx" (RelFrameId=1, Internal ID=1)
Action.c(63):     HTTP/1.1 200 OK\r\n
Action.c(63):     Cache-Control: private, max-age=0\r\n
Action.c(63):     Content-Type: text/xml; charset=utf-8\r\n
Action.c(63):     Content-Encoding: gzip\r\n
Action.c(63):     Vary: Accept-Encoding\r\n
Action.c(63):     Server: Microsoft-IIS/7.0\r\n
Action.c(63):     X-AspNet-Version: 4.0.30319\r\n
Action.c(63):     X-Powered-By: ASP.NET\r\n
Action.c(63):     Date: Fri, 04 Apr 2014 14:47:04 GMT\r\n
Action.c(63):     Content-Length: 725\r\n
Action.c(63):     \r\n
Action.c(63): t=813ms: 725-byte ENCODED response body received for "http://www.webservicex.com/globalweather.asmx" (RelFrameId=1, Internal ID=1)
Action.c(63): t=817ms: 1109-byte DECODED response body for "http://www.webservicex.com/globalweather.asmx" (RelFrameId=1, Internal ID=1)
Action.c(63):     <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.or
Action.c(63):     g/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://
Action.c(63):     www.w3.org/2001/XMLSchema"><soap:Body><GetWeatherResponse xmlns="http://www.webserviceX.NE
Action.c(63):     T"><GetWeatherResult>&lt;?xml version="1.0" encoding="utf-16"?&gt;\r\n
Action.c(63):     &lt;CurrentWeather&gt;\r\n
Action.c(63):       &lt;Location&gt;SEATTLE-TACOMA INTERNATIONAL  AIRPORT , WA, United States (KSEA) 47-27N
Action.c(63):     122-19W 136M&lt;/Location&gt;\r\n
Action.c(63):       &lt;Time&gt;Apr 04, 2014 - 09:53 AM EDT / 2014.04.04 1353 UTC&lt;/Time&gt;\r\n
Action.c(63):       &lt;Wind&gt; from the S (190 degrees) at 12 MPH (10 KT):0&lt;/Wind&gt;\r\n
Action.c(63):       &lt;Visibility&gt; 10 mile(s):0&lt;/Visibility&gt;\r\n
Action.c(63):       &lt;SkyConditions&gt; mostly cloudy&lt;/SkyConditions&gt;\r\n
Action.c(63):       &lt;Temperature&gt; 44.1 F (6.7 C)&lt;/Temperature&gt;\r\n
Action.c(63):       &lt;DewPoint&gt; 39.9 F (4.4 C)&lt;/DewPoint&gt;\r\n
Action.c(63):       &lt;RelativeHumidity&gt; 85%&lt;/RelativeHumidity&gt;\r\n
Action.c(63):       &lt;Pressure&gt; 29.94 in. Hg (1013 hPa)&lt;/Pressure&gt;\r\n
Action.c(63):       &lt;Status&gt;Success&lt;/Status&gt;\r\n
Action.c(63):     &lt;/CurrentWeather&gt;</GetWeatherResult></GetWeatherResponse></soap:Body></soap:Envelope
Action.c(63):     >
Action.c(63): Notify: Saving Parameter "ResponseBody = &gt; 44.1 F (6.7 C)&lt;".
Action.c(63): Registered web_reg_find successful for "Text=SEATTLE-TACOMA INTERNATIONAL  AIRPORT , WA, United States (KSEA)" (count=1)   [MsgId: MMSG-26364]
Action.c(63): web_custom_request("post_to_http_jms_provider") was successful, 725 body bytes, 277 header bytes   [MsgId: MMSG-26386]
Action.c(74): Notify: Parameter Substitution: parameter "ResponseBody" =  "&gt; 44.1 F (6.7 C)&lt;"
Action.c(74): Temp is<>: &gt; 44.1 F (6.7 C)&lt;
Action.c(80): Notify: Transaction "post_xml" ended with "Pass" status (Duration: 1.2061 Wasted Time: 0.6257).
Ending action Action.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.

Another advantage of this process is if we want to validate the response of web service and customize it , we have lr_xml functions ( refer LR help).

example : lr_xml_get_values().







No comments:

Post a Comment