在 SoapUI 中使用 groovy 脚本记录测试步骤响应

Log Test Step response using groovy script in SoapUI

我目前有一个包含 76 个 Soap 测试步骤的测试套件,其中所有步骤都是 运行。但是在日志中,我得到了预期的测试步骤名称,但没有响应。

groovy 脚本和测试步骤都在同一个测试套件中,但测试用例不同。它具有以下结构:

Groovy 脚本:

def testCases = context.testCase.testSuite.getTestCaseList()
testCases.each
{

    for(testSteps in it.testStepList)
    {
        log.info "~~~Test Step:" + testSteps.name
        def requestname = testSteps.name
        log.info context.expand('${'+requestname+'#Response}')
    }
}

日志:

Tue Mar 21 11:50:04 GMT 2017:INFO:~~~Test Step:TestStep_0001
Tue Mar 21 11:50:04 GMT 2017:INFO:
Tue Mar 21 11:50:04 GMT 2017:INFO:~~~Test Step:TestStep_0002
Tue Mar 21 11:50:04 GMT 2017:INFO:
Tue Mar 21 11:50:04 GMT 2017:INFO:~~~Test Step:TestStep_0003
Tue Mar 21 11:50:04 GMT 2017:INFO:

为什么我没有得到每个测试步骤响应中的数据?

这是 Groovy Script,它可以满足您的需求: 关键是使用 step.getPropertyValue('Response')

import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
//Repeat thru test cases
context.testCase.testSuite.testCaseList.each { tc ->
    tc.testStepList.each { step ->
        log.info "~~~Test Step:" + step.name 
        if (step instanceof WsdlTestRequestStep) {
            log.info step.getPropertyValue('Response')  
        } else {
            log.info 'Ignoring step as it is not SOAP request type step'
        }
    }
}