0

I am trying to retrieve a value from a XML response but it prints nothing.Please note that I am using SOAP UI to test the webservice and has written a simple piece of code to retrieve the policyid from the below response xml.

Below is the code; if you see the second line of screenshots of the, it prints EMPTY value.

SOAP UI Logs/Output

I tried different options suggested in various websites but nothing helped

Groovy Script

def response = context.expand( '${XMLService#Response}' )

def xml = new XmlSlurper().parseText(response);

log.info xml

log.info(xml.EQuoteResponse.Policy.PolicyId.text())
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

0

When you parse the xml, you're effectively at the root node in the result... So you don't need the EQuoteResponse when querying the document

log.info(xml.Policy.PolicyId.text())

Will work

tim_yates
  • 167,322
  • 27
  • 342
  • 338
0

This should work :

def tstStep =  testRunner.testCase.testSuite.testCases["yourTestCaseName"].testSteps["YourXMLRequestName"]
def response = tstStep.getPropertyValue("response")
def xml = new XmlSlurper().parseText(response)
log.info "PolicyId:::" + xml.Policy.PolicyId.text()
Novice Coder
  • 105
  • 1
  • 6