This topic contains examples of using properties in request parameters and bodies.
Using response data in subsequent requests
In this example, we use the SOAP Sample Project, shipped with ReadyAPI. In this project, we have the Simple Search Test Case test case that declares a username/password, calls a login action to get the session ID, then calls a search with the session id parameter, and finally calls the logout with the session ID parameter.
-
Open the Simple Search Test Case test case:
-
Open the Test Request – login test step and run the request.
Note: The test step sends a request to the virtual service, so make sure it is running: -
Expand the APIs (Virtual) node in the Navigator.
-
Right-click the virtual service and select Start.
In the response tab, you can see the received response:
-
-
Open the Test Request – logout test step.
-
This request already has a username parameter filled with the Property Transfer test step, but, for demonstration purposes, we will replace that with the property expansion.
In the Form panel, click the ellipsis button next to the sessionid field:
-
In the Get Data dialog, specify the Response property of the first SOAP Request test step and click Add:
-
ReadyAPI determines that the specified property contains an XML content and opens the Select XPath dialog. Select the sessionid element and click OK:
ReadyAPI specifies the property expansion to get the selected value.:
${Test Request – login#Response#declare namespace sam='http://www.soapui.org/sample/'; //sam:loginResponse[1]/sessionid[1]}
-
When you run the request again, you can see that the actual session ID value has been used in the Raw request view:
Passing data to JSON body
In this example, we will insert a randomly generated integer into a JSON request body.
We will use the Petstore service on SwaggerHub for the example. A PUT request to the https://petstore.swagger.io/v2/pet
endpoint updates an existing pet on the server using data from the JSON body:
-
Click Generate Values to add a data source. In the dialog window, click OK:
-
In the data source, create an
id
property and set its type to Integer: -
Now, we need to make the request retrieve this generated integer from the data source. In the request editor, clear the value of the
id
node, put the caret in place of the value, right-click, and select Get Data: -
In the dialog that appears, select the Data Source test step and the id property:
ReadyAPI will create a property expansion pointing to the data source property. It will resolve when you run the test and ReadyAPI will automatically insert the current value of the property into the JSON body.
Conditional inline property expansions
You can conditionally expand a property in a request or similar entities, using the third custom property’s value. For example, the selection test case property has the selection
value. To expand the myFirstXMLSnippet and mySecondXMLSnippet properties in it, use the following code:
Passing XML data by using property expansions
During the test run, ReadyAPI replaces the property expansion with the value of the property the expansion points to. In some cases, the value may be XML data. If ReadyAPI inserts it as is, the message format may break (the message may become ill-formed). To avoid this, include the property expansion in the CDATA section. For example:
<request_body><file><![CDATA[${DataSource#content}]]></file></request_body>
Note that you can insert CDATA only in the XML Editor.