[英]soapUI groovy script groovy.lang.MissingMethodException
Following exception is received when I tried to parse response within a soapUI test step.Also tried getXMLHolder method. 当我尝试在soapUI测试步骤中解析响应时,收到以下异常。还尝试了getXMLHolder方法。 Still no luck. 仍然没有运气。
Am I missing an import or library? 我是否缺少进口商品或图书馆?
groovy.lang.MissingMethodException: No signature of method: java.lang.String.getNodeValue() is applicable for argument types: (java.lang.String) values: [//ConversionRateResponse/ConversionRateResult] error at line: 16 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")
And the response is as follows 响应如下
<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>
You can add the Script Assertion
to the Soap Request Test step. 您可以将Script Assertion
添加到Soap Request Test步骤中。
Here is the script: 这是脚本:
//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
I can see you have used getNodeValue but on String which is wrong 我可以看到您使用了getNodeValue,但是在String上使用了错误
if you see your error it says, "No signature of method: java.lang.String.getNodeValue() is applicable for argument types: (java.lang.String) values " 如果看到错误,则会显示“没有方法签名:java.lang.String.getNodeValue()适用于参数类型: (java.lang.String)values ”
see the below code where we have used the getNodeValue on the correct thing 请参阅以下代码,在正确的地方使用了getNodeValue的代码
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def response = groovyUtils.getXmlHolder('SOAP Request#Response')
def refNum=response.getNodeValue("//*:ConversionRateResponse//*:ConversionRateResult")
log.info refNum
getNodeValue is a very useful function and will help a lot in extracting value from xml, Similarly we have getDomNode which is for the nodes and not values getNodeValue是一个非常有用的函数,它将对从xml中提取值有很大帮助,类似地,我们有getDomNode用于节点而不是值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.