Loadrunner scripting for Rest API services - web_custom_request

In this post we will see how to script a Rest API call in load runner.

Rest API details:

URL : https://10.36.133.105:8104/belocc/v2/belea/dealer/B1234/rep/B1234/smsession/10/consignments?access_token=800004e-c7ca-400b-9004-48c8aef00000

Method Type: 
POST (Apart from POST other methods used in Rest API's are GET, PUT, PATCH & DELETE)

Mode: HTTP

Encoding Type: application/json

Request Body:
{
    "code":"0032906789",
    "entries":[
        {
            "CEntryNumber":"",
            "orderEntry":{
            "entryNumber":"1",
            "quantity":"2"
            }
        }
       
    ]
}

Convert the Request body to the below loadrunner format (i.e) place '\' before every '"'.

{\"code\":\"0032906789\",\"entries\":[{\"CEntryNumber\":\"\",\"orderEntry\":{\"entryNumber\":\"1\",\"quantity\":\"2\"}}]}

save the formatted request body in a character pointer.

char *JsonReqInit;

char *JsonReqFinal;

JsonReqInit = "{\"code\":\"0032906789\",\"entries\":[{\"CEntryNumber\":\"\",\"orderEntry\":{\"entryNumber\":\"1\",\"quantity\":\"2\"}}]}";   //save the string in a C variable.

lr_save_string(lr_eval_string(JsonReqInit),"JsonReqFinal");

Goto Design --> Insert in Script --> New Step

Then Steps Tool search window will open in the right pane, search for web_custom_request and open it.



Enter the details in each field and click ok. Below request will get generated in the script.

web_custom_request("Rest_API",
"URL=https://10.36.133.105:8104/belocc/v2/belea/dealer/B1234/rep/B1234/smsession/10/consignments?access_token=800004e-c7ca-400b-9004-48c8aef00000",
"Method=POST",
"TargetFrame=",
"Resource=0",
"Referer=",
"Mode=HTTP",
"EncType=application/json",
"Body={JsonReqFinal}",      //Pass the variable in the body of the web_custom_request.
LAST);

23 comments:

  1. IntelliMindz is a best IT Training in Bangalore with placement, offering 200 and more software courses with 100% Placement Assistance.

    ETL Testing Course In Bangalore
    Selenium Training In Bangalore
    Java Training In Bangalore
    Loadrunner Training In Bangalore
    Test-Complete Training In Bangalore

    ReplyDelete