soapUI groovy脚本groovy.lang.MissingMethodException

时间:2018-02-21 16:08:01

标签: groovy soapui

当我尝试在soapUI测试步骤中解析响应时收到以下异常。还尝试了getXMLHolder方法。仍然没有运气。

我错过了导入或库吗?

  

groovy.lang.MissingMethodException:没有方法签名:   java.lang.String.getNodeValue()适用于参数类型:   (java.lang.String)值:   第一行[// ConversionRateResponse / ConversionRateResult]错误:16

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("FirstProject")
testSuite = project.getTestSuiteByName("TestSuite 1");
testCase = testSuite.getTestCaseByName("TestCase 1");
testCase.setPropertyValue("fromCurrency","EUR")
testCase.setPropertyValue("toCurrency","TRL")
testStep=testCase.testSteps["SOAP Request1"]

def responseHolder=testStep.getPropertyValue("response");

 def refNum = responseHolder.getNodeValue("//ConversionRateResponse/ConversionRateResult")

响应如下

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <ConversionRateResponse xmlns="http://www.webserviceX.NET/">
         <ConversionRateResult>-1</ConversionRateResult>
      </ConversionRateResponse>
   </soap:Body>
</soap:Envelope>

1 个答案:

答案 0 :(得分:1)

您可以将Script Assertion添加到肥皂请求测试步骤。

这是脚本:

//Check if the response is not empty
assert context.response, 'Response is empty or null'

def rate = new XmlSlurper().parseText(context.response).'**'.find{it.name() == 'ConversionRateResult'}?.text() as Integer
log.info "Conversion rate result is : $rate "

//Check if the result rate is -1, change if needed
assert -1 == rate