1

Need some help in loadrunner scripting with REST api. I have a requirement that LR script should always replace the unique parameter and this parameter should be part of Json body. File whatever i am using is huge. Hence, i created payload.json in extra files of LR. In Bodyfilepath i give this name of json file. In the payload.json i have parameterised a value (which needs to be unique every iteration) for request to be succesful. However, this paramter value is not getting replaced. Can anyone help me or share the code that helps to replace the value in the json file with the parameter value Thank you

web_custom_request(
"web_custom_request", 
"URL=name of the URL/Service ", 
"Method=POST", 
"TargetFrame=", 
"Resource=0", 
"Referer=", 
"BodyFilePath=payload.json", 
LAST); 

Payload.json file is passed under Extra Files and sample looks like this:

{ "Msgheader":
{ "Field1":"AB", "Field2":"201300{test}", "Field3":"50.00", "CrBy":"", "CrOn":"2018-03-16", }

4
  • 1
    Could you share your code so we can tell you what went wrong? Commented Mar 18, 2018 at 12:26
  • web_custom_request("web_custom_request", "URL=name of the URL/Service ", "Method=POST", "TargetFrame=", "Resource=0", "Referer=", "BodyFilePath=payload.json", LAST); Payload.json file is passed under Extra Files and sample looks like this: { "Msgheader":{ "Field1":"AB", "Field2":"201300{test}", "Field3":"50.00", "CrBy":"", "CrOn":"2018-03-16", }, i want the value of {test} to be changed which i am passing from the Paramters Commented Mar 18, 2018 at 12:31
  • You can edit your question with the code :) Commented Mar 18, 2018 at 12:32
  • Let me know if you need more details? Awaiting for answer :) Commented Mar 18, 2018 at 12:42

1 Answer 1

1

It appears you cannot do parameter substitution directly on a loaded file and therefore you need to manually load the JSON and then use it as body. Here is an example on how to do it:

lr_read_file("test.json", "test", 0);
lr_save_string(lr_eval_string(lr_eval_string("{test}")),"myjson");


lr_eval_json("Buffer={myjson}", 
             "JsonObject=myjson", 
             LAST);
lr_json_stringify("JsonObject=myjson","Format=compact","OutputParam=Result",LAST );


web_rest("My POST",
    "URL=http://myserver.com",
    "Method=POST",
    "EncType=raw",
    "Snapshot=t536990.inf",
//  "Body={\"store\": \"{ts}\"}", this is what the JSON contains 
//                                and I have a parameter named ts
    "Body={Result}",
    HEADERS,
    "Name=Content-Type", "Value=application/json", ENDHEADER,
    LAST);
Sign up to request clarification or add additional context in comments.

5 Comments

Awsome Mr.Buzzy. It worked for me :):) Thank you so much for responding fast!
Hello, I have a follow up query on the same topic.. Load testing with this code works.. But when i try to upload a big json file ( that has around 15k records around 260kb file), either vugen hangs or throws me error that "Cannot Open the File". So, is there a way i zip the json file and send? How to handle the big data here?
260kb is not a big file (we perform our tests with a 4mb file). Could you open a support ticket with the problem so that our support staff can identify which component causes the problem.
sure.. sorry. its 6 MB file. If LR should support this, then i will open ticket and clarify. Thanks
It should support it, especially in VuGen development mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.