使用 groovy 脚本 soapui 逐行比较失败的测试步骤对测试步骤 "assertion contains" 的响应

compare line by line failed teststep response to a teststep "assertion contains" using groovy script soapui

我一直在寻找一种方法来将失败测试步骤的响应与该测试步骤的 "contains" 断言进行比较,并将差异吐出到名为该测试步骤的日志文件中。听起来很简单:(

换句话说,我需要一个 groovy 脚本,它将位于测试用例的末尾,并且 运行 通过该测试用例中所有失败的测试步骤,然后比较响应中的每一行到测试步骤断言包含的相应行(它称为 Contains Assertion,它实际上是先前有效和工作响应的复制粘贴),然后我们需要将不同的行吐出到 log/file.这是我到目前为止的内容(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
        }
    }
}

没错!!我知道了!! (好的,除了比较位,但根据您的目标,有很多方法可以做到这一点)。感谢所有为此提供帮助的人:)

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;