SoapUI Groovy 脚本,log.info 有关测试步骤的详细信息 运行。

SoapUI Groovy Script, log.info detailed information about test steps run.

我在 SoapUI 中有一个 Groovy 脚本,它为每个 TestStep 记录该步骤通过或失败的天气。我希望 Groovy 脚本也记录出错的断言消息。

import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus

def TestCase = testRunner.getTestCase()
def StepList = TestCase.getTestStepList()
StepList.each{
    // check that testStep has assertionStatus 
    // (for example groovy testSteps hasn't this property since
    // there is no asserts on its)
    if(it.metaClass.hasProperty(it,'assertionStatus')){
        if(it.assertionStatus == AssertionStatus.FAILED){
            log.info "${it.name} FAILED"    

        }else if(it.assertionStatus == AssertionStatus.VALID){
            log.info "${it.name} Passed"
        }else if(it.assertionStatus == AssertionStatus.UNKNOWN){
            log.info "${it.name} UNKNOWN (PROBABLY NOT ALREADY EXECUTED)"
        }
    }
}

目前我得到这个输出:

Thu Oct 20 11:31:06 BST 2016:INFO:TestStep_0051 Passed
Thu Oct 20 11:31:06 BST 2016:INFO:TestStep_0052 FAILED
Thu Oct 20 11:31:06 BST 2016:INFO:TestStep_0053 Passed

我希望失败的断言能够更详细地显示失败原因的消息。它是失败的 TestStep 本身,我收到消息:

assert node.toString().matches("(0|175.238|0)\d*")       |    |          |      |    |          false           |    132.497286826667           132.497286826667

此外,当我 运行 这个 Groovy 脚本时,会弹出一个标题为 'Information' 的 window,它只有黑色背景,而且太宽了,我看不出来找到它的右边。有人知道这是什么吗?

你可以试着修改一下你的代码,让我解释一下:

您可以使用 getAssertionList() 访问测试步骤的所有断言,而不是通过元类仅访问测试步骤结果的最终 AssertionStatus,以避免出现不包含断言的测试步骤问题,您可以检查这个方法存在使用 metaClass.

然后对于此列表中的每个断言,您可以检查状态,对于失败的断言,您可以使用 getErrors() 方法获取错误消息。

最后为了避免因为默认Groovy return最后一个实例化对象(在你的脚本StepList)和SOAPUI提示它而产生的提示消息,你可以添加return 语句到 return 什么都没有,避免提示效果。

import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus

def TestCase = testRunner.getTestCase()
def StepList = TestCase.getTestStepList()
StepList.each{

    // check that this kind of testStep
    // can contain assertions (avoid errors with groovy testSteps)
    if(it.metaClass.respondsTo(it,"getAssertionList")){

         def assertions = it?.getAssertionList()

         assertions?.each{ assertion ->

            if(assertion?.getStatus() == AssertionStatus.FAILED){
              log.info "${it.name} FAILED"
               assertion?.getErrors()?.each{ error ->
                 log.info "Error message ${error.getMessage()}"
               }
            }else if(assertion?.getStatus() == AssertionStatus.VALID){
                log.info "${it.name} Passed"
            }else if(assertion?.getStatus() == AssertionStatus.UNKNOWN){
                log.info "${it.name} UNKNOWN (PROBABLY NOT ALREADY EXECUTED)"
            }
         }
     }
}
return