How to passing json parameters for test api (restful) in katalon studio?

陌路散爱 提交于 2021-01-28 14:13:00

问题


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.

In my Katalon test I tried to do that in the script tab:

My parameters are not sent to the API...

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.


回答1:


You didn't add parameters to the REST object.

Click the + Add button shown in the screenshot and add the following to the parameter table:

Name    |  Value
--------------------
name    |  ${name}
job     |  ${job}

That will change your request to https://reqres.in/api/users?name=${name}&job=${job} so when you send the request as you did in the OP, Ema and developer will go to the place of the placeholders for name and job.




回答2:


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.

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)


来源:https://stackoverflow.com/questions/56430247/how-to-passing-json-parameters-for-test-api-restful-in-katalon-studio

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