Scripting Web Services in Load Runner


Below are the steps to follow for scripting web services to load testing.
  • Get WSDL - Also called endpoint
  • Get Request XML - Also called request payload
  • Test in SOAP UI/POSTMAN - Test manually if proper response payload in fetched
  • Open Load Runner. Open new script with protocol as Web Services.
  • Go to Action page.
  • Go to View in Menu bar, click Step ToolBox.
  • Search web_customer_request.
Fill the below details:
METHOD: POST
POST requests supply additional data from the client (browser) to the server in the message body. In contrast, GET requests include all required data in the URL.
URL : your wsdl
Body: Copy and paste entire request. select all and right. Convert to C.

Click OK.

  • Now add below line above your web_custom_request:

web_reg_save_param("c_response","LB=<responseCode>","RB=</responseCode>","ORD=1");
lr_start_transaction("client_project_application_transaction_name");

After this will be your web_custom_request code:
web_custom_request("web_custom_request",
.
.
.
"</soapenv:Envelope>",
LAST);


  • Finally below code to check if you received pass response code or failed. You can add more validation in request response.

if (strcmp (lr_eval_string("{c_response}"),"3001") == 0)
        {
           lr_end_transaction("ngcc_bcm_retrieve_voucher_info", LR_PASS);
           
        }

else
{
lr_end_transaction("ngcc_bcm_retrieve_voucher_info",LR_FAIL);
  //lr_output_message ( "Response Ticket#%s", lr_eval_string ( "{c_ticket}" ) );

            lr_continue_on_error( 0 );
            lr_exit( LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL );
}

Web functions in loadrunner

web_reg_save_param
web_reg_save_param is THE most important function when you are working with LoadRunner. It is used for correlation.
web_req_save_param(“c_sessionid”,“NOTFOUND=ERROR”,”LB=Session”,”RB=}”,“ORD=1”,LAST);

web_set_max_html_param_len

To retrieve a string longer than 256 characters, use web_set_max_html_param_len to increase the maximum valid length.
web_set_max_html_param_len("1024");

web_custom_request

Allows you to create a custom HTTP request with any method supported by HTTP. We usually use it for web service scripting and method could be used from Step Toolbox in View Menu in Menu bar of Load Runner. It includes End point, Method (GET/POST), Body (Request payload) etc.

web_global_verification

web_global_verification("Text=Exception","Fail=Found","ID=MyAPP",LAST); 
In this example if the string Exception is found, the script execution stops.

web_add_auto_header:
web_add_auto_header function is used to add header to all the consecutive HTTP requests. It happens that you need to pass the log on session id in all the subsequent HTTP request and this can be done with this function,

Syntax : web_add_auto_header( const char *Header, const char *Content );
Example : web_add_auto_header("Authorization",lr_eval_string("{c_token}"));
                    web_add_auto_header("pwd", "northanger1803");