【问题标题】:Run generic groovy script assertion in SoapUI在 SoapUI 中运行通用 groovy 脚本断言
【发布时间】:2019-04-12 07:57:59
【问题描述】:

是否可以/如何从 SoapUI 断言运行 groovy 脚本,而无需将脚本复制/粘贴到需要执行相同脚本的所有测试步骤中?是否可以在断言之外编写脚本并像调用方法一样运行脚本?这样您就可以在多个测试步骤中重用断言脚本。

到目前为止,我已经尝试从断言中调用一个 groovy 测试步骤,但是 run() 方法需要一个 testRunner 变量,而该变量在断言中是不可用的。我还尝试编写一个 groovy 脚本作为后续测试步骤(不是断言),该脚本调用另一个 groovy 测试步骤脚本,但我无法将响应从一个测试步骤转移到下一个测试步骤(老实说,我宁愿不创建实际上只是断言的测试步骤)。

注意:这不是 How to create variables in soapui test case that can be accessed across all test steps - groovy test step & script assertion test step? 的重复,因为该问题涉及存储属性,而不是重用脚本。

【问题讨论】:

  • 您在寻找“脚本库”吗? soapui.org/scripting-properties/…
  • @SiKing 的评论应该是,恕我直言,是答案。我写了几个断言类,但我用 Java 编写了它们并将它们存储在 SoapUI 安装的脚本文件夹中。您仍然需要在测试中执行常规步骤来调用外部脚本,但如果您的检查发生更改,您只需在一处更新外部脚本。
  • @ChrisAdams 解决方案需要是可移植的,即项目 xml 将被移交给多个人。将单独的文件作为库加载到soapui中似乎会给可移植性增加一层复杂性。我真的希望解决方案在项目层和 SoapUI 屏幕本身上可见(并可编辑)。

标签: groovy soapui assertion


【解决方案1】:

我终于能够找出我的第二种方法:添加另一个 groovy 脚本作为具有断言并传递响应的后续测试步骤。脚本是:

context.response = context.expand('${MyTestStep#Response}') // store response to context variable
Object result = testRunner.testCase.testSuite.testCases['Validate Response'].testSteps['Validate Response'].run(testRunner, context)

if(result.getError() != null) {
    log.error("error", result.getError())
    assert false
}
assert true

MyTestStep 是 groovy 脚本之前的测试步骤。 Validate Response 是 groovy 脚本的测试用例名称,也称为Validate Response,通过run 方法执行。

【讨论】:

  • 如果您使用 Ready API (Pro),您可以创建一个脚本库,您可以像函数一样调用它
  • 如果我的经理给我 SoapUI Pro 绿灯,我会记住这一点。
  • 不需要“断言为真”。更好的形式是这样断言你的谓词:“assert result.getError() == null : result.getError()”
  • 没错,assert true 是多余的。我删除了它。 assert false 仍然存在,因为我需要在抛出错误断言之前记录错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-19
相关资源
最近更新 更多