【问题标题】:How can I capture soapui assertions list with status如何捕获带有状态的 soapui 断言列表
【发布时间】:2015-07-01 16:25:52
【问题描述】:

如果您运行 testStep 并查看断言。 SoapUI 返回断言绿色/红色以及添加“- VALID”或“- FAILED”

问题:有没有办法捕获完整的字符串? 名字+状态

即 SOAP 响应 - 有效 XPath 匹配 - 有效 包含 - 有效 不包含 - 失败

目前我正在提取 assertionsList - 但我希望额外的状态片段随之而来。

谢谢你, 抢

【问题讨论】:

  • 是的,可以使用 groovy 脚本获取断言的名称并将状态附加到它,您能否分享您的实际 groovy 代码以使用它以便给您一个可能的答案? :)

标签: groovy soapui assertions


【解决方案1】:

要打印来自testCase 内所有testSteps 的所有断言,您可以在testCasetearDown script 中使用以下常规脚本,它使用返回TestAssertion 列表的getAssertionList(),然后使用labelstatus 属性对其进行迭代:

testRunner.testCase.testSteps.each{ name,props ->
    log.info "Test step name: $name"
    // check that the testStep class support assertions 
    // (for example groovy testStep doesn't)
    if(props.metaClass.respondsTo(props, "getAssertionList")){
        // get assertionList
        props.getAssertionList().each{
           log.info "$it.label - $it.status"
        }
    }
}

注意:并非所有类型的 testStep 都有断言(例如 Groovy 脚本 testStep 没有),因此有必要在使用前检查它getAssertionList()

如果您想从一个特定的testStep 获取所有断言,您可以在 groovy 脚本中使用相同的方法:

// get the testStep
def testStep = testRunner.testCase.getTestStepByName('Test Request')

// check that the testStep specific class support assertions 
// (for example groovy testStep doesn't)
if(testStep.metaClass.respondsTo(testStep, "getAssertionList")){
    // print assertion names an its status
    testStep.getAssertionList().each{
       log.info "$it.label - $it.status"    
    }
}

希望对你有帮助,

【讨论】:

  • 这似乎确实循环了正确的事情,但是 getAssertionList() 部分在错误日志中给了我这个:“错误:groovy.lang.MissingMethodException:没有方法签名:com.eviware。 soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.getAssertionList() 适用于参数类型:() 值:[]"
  • @laurencemadill 我会更新我的回复以避免您的问题。问题是 Groovy 脚本 测试步骤(使用 com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestS‌​tep 实现的没有断言。
  • 优秀。我应该在我的身上发现这一点。非常感谢你,我已经赞成你的回答
  • 如果你想去掉循环中的if,你可以在each之前过滤:testSteps.findAll { it.respondsTo('getAssertionList') }.each{ name,props -> /* work with assertionList */ }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多