how to parameterize the value in json file - loadrunner

故事扮演 提交于 2019-12-24 10:40:24

问题


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);


来源:https://stackoverflow.com/questions/49347798/how-to-parameterize-the-value-in-json-file-loadrunner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!