使用groovy脚本soapui逐行比较,testtep响应testtep“assertion contains”

时间:2015-06-11 12:32:39

标签: groovy soapui assertion

我一直在寻找一种方法来比较失败的测试步骤的响应与该测试步骤的“包含”断言,并将差异吐出到名为teststep的日志文件中。听起来很容易:(

换句话说,我需要一个groovy脚本,它将位于测试用例的末尾,并在该测试用例中运行所有失败的测试步骤,然后将响应中的每一行与其中相应的行进行比较。测试步骤断言包含(它称为包含断言,它实际上是先前有效和工作响应的复制粘贴)然后我们需要将不同的行吐出到日志/文件中。这是我到目前为止(rad,我修复了以前的错误)

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

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

StepList.each
{
    if(it.metaClass.hasProperty(it,'assertionStatus'))
    {
        if(it.assertionStatus == AssertionStatus.FAILED)
        {
            def ass = it.getAssertableContentAsXml()
            def res = it.getTestStep().getPropertyValue('Response')
            log.error "Test Step: ${it.name} " + "${it.assertionStatus}"
            log.info ass 
            log.info res
        }
    }
}

1 个答案:

答案 0 :(得分:0)

RIGHT !!我知道了!! (确定除了比较位,但有很多方法可以做到这一点取决于你的目标)。感谢所有帮助过这一点的人:)

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

def TestCase = testRunner.getTestCase()
def StepList = TestCase.getTestStepList()
//Going through each step
StepList.each
{//check for property and declare it
    if(it.metaClass.hasProperty(it,'assertionStatus'))
    {//using it to check AssertionStatus
        if(it.assertionStatus == AssertionStatus.FAILED)
        {//ass=Assertion res=Response of step
            def ass = ""
            def assList = testRunner.getTestCase().getTestStepByName("${it.name}").getAssertionList()
            for(x in assList)
                {
                    ass = x.getToken().toString()
                }
            def res = it.getTestStep().getPropertyValue('Response').toString()
            log.error " Test Step: ${it.name} " + "${it.assertionStatus}"
            log.info "Response: "+res
            log.info "Assertion: "+ass
            //compare assertion to response and log differences

        }
    }
}
return;