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

时间:2016-10-20 10:42:24

标签: logging groovy soapui assertions

我在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脚本时,会弹出一个标题为“信息”的窗口,该窗口只有黑色背景,而且很宽,我似乎无法找到它的右侧。有谁知道这是什么?

1 个答案:

答案 0 :(得分:2)

您可以尝试稍微修改一下代码,让我解释一下:

您可以使用getAssertionList()访问testStep的所有断言,而不是仅通过metaClass访问testStep结果的最终AssertionStatus,以避免不包含断言的testSteps的问题,您可以检查这个使用metaClass存在方法。

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

最后,为了避免生成的提示消息,因为默认情况下Groovy返回最后一个实例化对象(在脚本StepList中)并且SOAPUI提示它,你可以添加一个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