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
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答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);