如何使用 Groovy 脚本测试步骤在 SOAPUI 中触发 REST 请求

How to trigger REST request in SOAPUI with Groovy script test step

使用下面的脚本,我可以将 data/payload 发送到我的 POST 请求。但是,值得注意的是 运行 来自脚本的 post 请求。需要 post 循环请求。

def POSTForgivness = testRunner
   .testCase
   .getTestStepByName("postforgivness")
   .getT‌​estRequest() 
POSTForgivness.setRequestContent(ForgivnessPayload)

来自评论的其他信息:

循环中需要 post 个请求。

这听起来像是数据驱动测试,而不是负载测试。

将您的 post-宽恕请求放在 'Data Source' 步骤和 'Data Source Loop' 步骤之间。

然后,您可以 'loop' 遍历 post-宽恕步骤,次数与数据源步骤中设置的行数一样多。对于您设置的每一行,您可以将负载定义为 'squirt' 到您的请求中。

SoapUI 网站上有一篇很棒的文章https://www.soapui.org/data-driven-tests/functional-tests.html

给你:sudo 代码

  1. 按名称获取测试步骤
  2. 将新请求设置为下一步
  3. 运行步骤
  4. 需要禁用其余步骤,因为每件事都由步骤 1(即 groovy 脚本步骤)控制
//Get the next step
def nextStep = context.testCase.getTestStepByName("postforgivness")
//Set the new request
nextStep.httpRequest.requestContent = ForgivnessPayload
//run next step
nextStep.run(testRunner, context)

只需循环上面的代码,直到完成数据