1

I have run SOAP API request and get the response as below using robot framework.

(reply){
   return = "PGP-98-Sq0awmdslfjsdssdlsifTvZUORTLe1fgVeUwaolR14QS"
}

I would like to retrieve the value PGP-98-Sq0awmdslfjsdssdlsifTvZUORTLe1fgVeUwaolR14QS from the response XML. I have tried to get the value using the command

${token}=    Set Variable    ${API_response_Data.return} 

But it throws an error

SyntaxError: unexpected EOF while parsing (<string>, line 1)

The actual response from the SOAP UI tools looks like below (This is just for reference).

<soapenv:Envelope xmlns:soapenv="something" xmlns:xsd="something">
   <soapenv:Body>
      <ns1:response xmlns:ns1="http://something.com">
         <return>PGP-98-Sq0awmdslfjsdssdlsifTvZUORTLe1fgVeUwaolR14QS</return>
      </ns1:response>
   </soapenv:Body>
</soapenv:Envelope>

I have used Parse XML keyword and I get the below error. enter image description here

and when I use

 ${Token}=    Get Element    ${API_response_Data}    .//*return
    Log    ${Token.text}

I get the below error. enter image description here

Please let me know how to extract the value from the return tag?

JCDani
  • 307
  • 7
  • 20

2 Answers2

1

You could use robot framework's XML library to parse the response XML and then get the text of the specific element. For example:

Demo
    ${root}=    Parse XML   soap_res.xml
    ${return}=  Get Element     ${root}     .//*return
    Log     ${return.text}

The Get Element keywords returns an XML element object, you need its text attribute. The output is the following:

enter image description here

Bence Kaulics
  • 7,066
  • 7
  • 33
  • 63
  • I get the error when using the keyword you have suggested. I have modified the question to add the error I get when using these keywords. Please help in resolving the issue. – JCDani Dec 09 '18 at 15:48
  • @JCDani The `${API_response_Data}` variable is not an XML so what I have suggested would not work. It should work if you could pass the actual response from the SOAP UI as an XML with all the tags. A. Kootstra has a suggestion for doing that. – Bence Kaulics Dec 09 '18 at 16:44
1

The SudsLibrary depends on the Suds module. Sadly this module is no longer maintained and as time passes the limitations of this module are becoming clearer.

In your case the object that is returned is difficult to use. This is why I preferred to have the XML response returned and process it myself using the standard XML library.

Before sending the request you can use the Set Return XML keyword to enable this. Then follow the example in the XML library for keyword Parse XML to obtain the actual value

A. Kootstra
  • 6,827
  • 3
  • 20
  • 43