1
votes

Following exception is received when I tried to parse response within a soapUI test step.Also tried getXMLHolder method. 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

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>
2
Can you show the response? - Rao
edited the question accordingly. - desperado06
Do you need any further processing after extracting the value? - Rao
The value will be saved to an excel sheet - desperado06
Ok. At least for the original question, extracting the required data is provided and how to asserts is shown the solution. Please see if that solves. - Rao

2 Answers

1
votes

You can add the Script Assertion to the Soap Request Test step.

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
1
votes

I can see you have used getNodeValue but on String which is wrong

if you see your error it says, "No signature of method: java.lang.String.getNodeValue() is applicable for argument types: (java.lang.String) values"

see the below code where we have used the getNodeValue on the correct thing

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