Store a value from XML/XPath output of a REST query in a SoapUI property for later use
I'm new to SOAP, REST, and SoapUI. I'm working to build a test case that simulates a user login & then extracts the user list from the server. My log in command is working, and I get the XML output I want:
<MGRestTokenResponse xmlns="http://schemas.datacontract.org/2004/07/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Message>success</Message>
<Token>---THIS IS THE DATA I WANT---</Token>
</MGRestTokenResponse>
I'm trying to get the Token value stored in a SecurityToken property inside SoapUI but nothing is working. I've tried using XmlToolBox to get an XPath result and I've been given:
/MGRestTokenResponse[@xmlns="http://schemas.datacontract.org/2004/07/"]/Token/text()
or
/MGRestTokenResponse[@xmlns="http://schemas.datacontract.org/2004/07/"]/Token/text()
but nothing I'm trying is working.
The environment I'm working in is REST only. How do I extract values from the responses & transfer them to a property?
After posting on StackOverflow, I finally got an answer to this. The Groovy Code I posted previously *is* one way to get the Token. However, I was more interested in getting the XML property directly in the Property Transfer step.
To do this, I set the Source to the previous request (GetSecurityToken) and set the Property to Response, Path language XPath. Now; inside the txt field for Source I needed to palce the following:
declare namespace ns1='http://schemas.datacontract.org/2004/07/'; //ns1:MGRestTokenResponse[1]/ns1:Token[1]
For the Target, I specify my test step properties and then the sectoken property. This causes the XML value to be transfered in a single step versus storing the entire output & using Groovy code to extract it.