如何在katalon studio中为测试api(restful)传递json参数? [英] How to passing json parameters for test api (restful) in katalon studio?
问题描述
我使用 reqres.in 假数据 API 创建了一个演示测试.我想创建一个有名字和作业参数的用户,但是需要的数据格式是json.
I created a demo test using reqres.in fake data API. I want to create a user with a name and a job parameter, but the data format required is json.
在我的 Katalon 测试中,我尝试在脚本选项卡中执行此操作:
In my Katalon test I tried to do that in the script tab:
我的参数没有发送到 API...
My parameters are not sent to the API...
我在 Katalon Studio (5.7) 中没有找到如何做到这一点,我不知道是否可以做到这一点.
I didn't find how to do that in Katalon Studio (5.7) and I don't know if it's possible to do that.
推荐答案
终于找到了解决方案,例如我想用refresh_token_key获取一个新的token,并以json格式发送并修改我的请求对象.
Finally, i 've found a solution, for exemple i want to get a new token with a refresh_token_key, and send it in json format and modify my request object.
我得到了我的 refresh_token_ken,把它放在一个字符串变量中,得到我的请求对象并像这样修改正文:
I get my refresh_token_ken, put it in a string variable, get my request object and modify the body like this :
RequestObject roRefresh_Token = findTestObject('Authentication/Refresh Token');
def jsonStr = "{'RefreshToken':'"+GlobalVariable.Refresh_Token+"'}";
roRefresh_Token.setBodyContent(new HttpTextBodyContent(jsonStr, "UTF-8", "application/json"));
WS.sendRequest(roRefresh_Token)
这篇关于如何在katalon studio中为测试api(restful)传递json参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!