cancel
Showing results for 
Search instead for 
Did you mean: 

How to 'GetData' from an xsd:string

SOLVED
CByler
Contributor

How to 'GetData' from an xsd:string

I am perplexed. I have a test case that generates a new and unique UserAPIKey for each iteration. I then have a test case following where I need to get that unique guid (as shown below) and pass it to a delete method to remove it. However, I can't for the life of me figure out how to grab just that guid and use it in the next test case. Can anyone offer advice? I am using ReadyAPI 3.5.0 with a Soap Web Service. Many thanks!

 

<NewDataSet>
<UserAPIKey>
<UserID>37</UserID>
<UserName>cbyler</UserName>
<FullName>Cherice Byler</FullName>
<UserAPIKey>68c4570c-b184-4865-871d-45ec083f9511</UserAPIKey>
</UserAPIKey>
</NewDataSet>

1 ACCEPTED SOLUTION

Accepted Solutions
troyyerJP
New Contributor

Re: How to 'GetData' from an xsd:string

@CByler wrote:

Wait, I found it. I needed to go up a higher level to the Test Case rather than the Test Step. It worked the first time I did it, however, it seems that SampleXML and GUID Custom Test Case Property values are being retained.....


So you are actually performing an incorrect selection which is causing this issue. At your Test Case Level (Your Test Case is DeleteUserAPIKey), there will be a Property Transfer Test Step that you have named SampleXML. So what is happening, is that every time, you are running the test case, your Property Transfer Step, is retrieving data from itself (The property transfer step has a guid that is not changing) and not the response that has the new guid. Hence why the new guid is not being retrieved. 

 


@CByler wrote:

 don't have the selection of SampleXML in the Property drop-menu

....


Note that in my sample, I named a Custom Test Case Property SampleXML to play around with the data you provided as I dont have the same request/response in my system. In your sample you have named a Property Transfer Test Step SampleXML. This is 2 different things. I hope you have this clear. 

 

If you have a look at point 3 in the Transfer properties page (https://www.soapui.org/docs/functional-testing/properties/transferring-properties) you will see that you would need to select the supplied response from the test step

troyyerJP_1-1616540648748.png

 

 So looking at your screenshot

In Step 2, the Property Transfer step that you named SampleXML  

Source is your the request step AddUserAPIKey (correct)

Property should be Response (because you receive the guid in the Response sent back to you by the service you are invoking with your request in Step 'AddUserApiKey'...you would not see SampleXML)

troyyerJP_0-1616540105086.png

once you select Response, the far right icon to select the field should now show the right data.

View solution in original post

11 REPLIES 11
nmrao
Community Hero

Re: How to 'GetData' from an xsd:string

1. You can use XmlSlurper to parse the xml and retrieve the data required. Use below documentation for the same.
https://groovy-lang.org/processing-xml.html
2. Once extracted, set the value at test suite level so that it can accessed in any of the tests using property expansion.
https://www.soapui.org/docs/scripting-and-properties/property-expansion/


Regards,
Rao.
CByler
Contributor

Re: How to 'GetData' from an xsd:string

I appreciate the response. I will give it a shot first thing Monday. Thanks! 

racharla
New Contributor

Re: How to 'GetData' from an xsd:string

When you right click on the field  where you want to replace the data, are you not seeing the Get Data dialog pop up? 

CByler
Contributor

Re: How to 'GetData' from an xsd:string

Sure. But when I get data the entire xml response is contained within the xsd:string and there's no way for me to just parse the guid out to use in the next test case.

troyyerJP
New Contributor

Re: How to 'GetData' from an xsd:string

I have done this in 2 ways

1) Using a combo of Property transfer Step and Properties Step (you dont need the Properties step as you could create Custom Properties at Project/Test Suite/Test Case levels) 

with a licensed ReadyAPI you can follow the steps provided here to do what you are after 

https://www.soapui.org/docs/functional-testing/properties/transferring-properties/ 

I do this to capture the SessionsId and Url after the Login Request Step.

 

2) transfer from a 'Groovy Script Test Step'/'Groovy Assertion' in the Request Step

something like this could work for you

 

 

 

/* Sample XML supplied. 
<NewDataSet>
<UserAPIKey>
<UserID>37</UserID>
<UserName>cbyler</UserName>
<FullName>Cherice Byler</FullName>
<UserAPIKey>68c4570c-b184-4865-871d-45ec083f9511</UserAPIKey>
</UserAPIKey>
</NewDataSet>
*/

//pull the request data into the groovy Assertion step (Assuming that the xml is from the current request step)
def Xmlnodes = new XmlParser().parseText(messageExchange.responseContentAsXml)
def ActualUserAPIKey = Xmlnodes.'**'.'UserAPIKey'.'UserAPIKey'.text()
/*
 note that you have 2 nodes for UserAPIKey.
first higher node Xmlnodes.'**'.'UserAPIKey'.text(), will get you:
37cbylerCherice Byler68c4570c-b184-4865-871d-45ec083f951168c4570c-b184-4865-871d-45ec083f9511
second inner node Xmlnodes.'**'.'UserAPIKey'.'UserAPIKey'.text() will get you: 68c4570c-b184-4865-871d-45ec083f9511
*/
//save value to a property to be called by other Test Steps
context.testCase.testSuite.setPropertyValue("RequestUserAPIKey", ActualUserAPIKey)

 

 

CByler
Contributor

Re: How to 'GetData' from an xsd:string

Awesome, thank you for the details troyyerJP!

CByler
Contributor

Re: How to 'GetData' from an xsd:string

troyyerJP, I tried using the Property Transfer as outlined in the first solution. I am at least able to get the data transfered to the next test step in the UserAPIKey* field, however, it's giving me the entire "AddUserAPIKeyResult" in the field and I don't have a way to just pass the guid value rather than the whole xml value (see screenshot). I then tried you second solution but failed spectacularly as it was outside my wheel house and I'm not quite that advanced with ReadyAPI.  Is there a way for me to just get that guid value?

troyyerJP
New Contributor

Re: How to 'GetData' from an xsd:string

Have you selected the right xml field from the field selector in the property transfer step?

troyyerJP_0-1616467773082.png

 


I've created a gif of what you could do with the property transfer stepHelp With GetData.gif

 

CByler
Contributor

Re: How to 'GetData' from an xsd:string

So, I tried to do it like you did it, however, in the Property Transfer, I don't see what you see. When I select the test step for the Property Transfer, then select the test step for AddUserAPIKey from the Source drop-menu, I don't have the selection of SampleXML in the Property drop-menu. See screenshots.  Thank you so much for helping me with this!

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors