如何在 groovyScript 中获取 testStep responseAsXml

How to get testStep responseAsXml in groovyScript

关于 soapUI 和 groovy,我试图将 XML 中的断言(工作)和响应都放入一个变量中。我收到错误

groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.getResponseAsXml() is applicable for argument types: () values: [] error at line: 6

我试过添加 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep 但还是想不通。我又尝试了一次消息交换,但也无济于事——据我所知,您实际上不能在此特定实例中使用 messageExchange

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.getResponseContentAsXml()

            log.error "${it.name} " + "${it.assertionStatus}"
            log.info ass + res

        }
    }
}

如果你想从com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep, a possible way is first get the testStep from this class using getTestStep()方法中得到响应。

此方法 returns class com.eviware.soapui.model.testsuite.TestStep, from this object you can get the testSteps properties like request, response, endpoint... using getPropertyValue(java.lang.string) 方法的一个对象。

因此,在您的情况下,要获得响应,请使用:

def res = it.getTestStep().getPropertyValue('Response')

而不是:

def res = it.getResponseContentAsXml()

由于@tim_yates评论了这种情况下的异常描述很清楚,所以下次请看一下SOAPUI api和答案中提供的链接:).

希望这对您有所帮助,