如何在Katalon中使用setBodyContent(HttpBodyContent)

时间:2018-04-26 17:42:58

标签: api testing jira-rest-api katalon-studio

一旦Katalon测试完成运行,我一直在尝试更新我们的测试管理API。

我们在JIRA中使用Adaptavist测试管理。 我不是想尝试更新Katalon JIRA插件。

针对Adaptavist的API调用需要是一个POST并且具有项目的正文消息,例如示例{“projectKey”:“FVS”,“testCaseKey”:“FVS-T1”,“status”:“Pass “,”“环境”:“DEV”} 我最终会用适当的Katalon测试结果变量替换这些项目。

我在对象存储库中创建了一个处理身份验证设置的服务调用,如果我在编辑器中使用这些样本值测试请求,这可以正常工作。

当我在Test Case本身添加脚本时,我很难让它工作,更不用用实际值替换变量了。

我目前有这个:

//run test
WebUI.openBrowser('')

WebUI.navigateToUrl(GlobalVariable.MainURL)

WebUI.verifyElementClickable(findTestObject('img_img-responsive_1'))

WebUI.verifyElementClickable(findTestObject('img_img-responsive_2'))

WebUI.verifyElementClickable(findTestObject('img_img-responsive_3'))

WebUI.closeBrowser()

//update JIRA
RequestObject getJIRAUpdateObject = (RequestObject)findTestObject('Web Service 
Calls/Update JIRA')

String vsRequestBody = '{"projectKey": "FVS",  "testCaseKey": "FVS-T1",  
"status": "Pass", "environment": "DEV"}';

body = getJIRAUpdateObject.setHttpBody(vsRequestBody)

WS.sendRequest(getJIRAUpdateObject)

我还有以下额外的导入

import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.RequestObject

现在在脚本编辑器中,我被告知setHttpBody现在在Katalon版本5.4+中折旧(我使用的是5.4.1)而我应该使用setBodyContent(HttpBodyContent)代替,但是当我查看API文档时,我无法弄清楚我应该如何使用它的语法。

有谁知道我应该如何更改代码,或者有我需要更改上述代码以使用这种新方法的示例?

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

As answered on the Katalon forum:

在您的情况下,正文内容为文本正文,则合适的实现应为:

import com.kms.katalon.core.testobject.impl.HttpTextBodyContent //for text in body
import com.kms.katalon.core.testobject.impl.HttpFileBodyContent //for file in body
import com.kms.katalon.core.testobject.impl.HttpFormDataBodyContent //for form data body
import com.kms.katalon.core.testobject.impl.HttpUrlEncodedBodyContent //for URL encoded text body

setBodyContent(new HttpTextBodyContent(your_text))

(API docs for HttpBodyContent implementation.)