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", }

Peter Wippermann
  • 4,125
  • 5
  • 35
  • 48
  • 1
    Could you share your code so we can tell you what went wrong? – Buzzy Mar 18 '18 at 12:26
  • web_custom_request("web_custom_request", "URL=https://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 – Lavanya Shenoy Mar 18 '18 at 12:31
  • You can edit your question with the code :) – Buzzy Mar 18 '18 at 12:32
  • Let me know if you need more details? Awaiting for answer :) – Lavanya Shenoy Mar 18 '18 at 12:42

1 Answers1

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);
Buzzy
  • 2,905
  • 3
  • 22
  • 31
  • Awsome Mr.Buzzy. It worked for me :):) Thank you so much for responding fast! – Lavanya Shenoy Mar 18 '18 at 14:20
  • 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? – Lavanya Shenoy Mar 22 '18 at 08:57
  • 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. – Buzzy Mar 22 '18 at 09:57
  • sure.. sorry. its 6 MB file. If LR should support this, then i will open ticket and clarify. Thanks – Lavanya Shenoy Mar 22 '18 at 10:43
  • It should support it, especially in VuGen development mode. – Buzzy Mar 22 '18 at 11:46