Examples of Using Properties

Applies to ReadyAPI 3.57, last modified on December 19, 2024

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:

    Add to 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:

    Testing web services with ReadyAPI: Received response

    Click the image to enlarge it.

  • 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:

    Testing web services with ReadyAPI: The Form panel

    Click the image to enlarge it.

  • In the Get Data dialog, specify the Response property of the first SOAP Request test step and click Add:

    Testing web services with ReadyAPI: Get Data dialog

    Click the image to enlarge it.

  • 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:

An example request to the Swagger Petstore service

Click the image to enlarge it.

  1. Click Generate Values to add a data source. In the dialog window, click OK:

    Pass data to JSON body: Add data source

    Click the image to enlarge it.

  2. In the data source, create an id property and set its type to Integer:

    Pass data to JSON body: Configure data source

    Click the image to enlarge it.

  3. 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:

    Pass data to JSON body: Create property expansion
  4. In the dialog that appears, select the Data Source test step and the id property:

    Pass data to JSON body: Select 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.

Pass data to JSON body: JSON body with property expansion

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:

${= testCase.getPropertyValue( "selection" ) == "first" ? testCase.getPropertyValue( "myFirstXMLSnippet" ) : testCase.getPropertyValue( "mySecondXMLSnippet" )}

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.

See Also

About Properties
Transferring Property Values

Watch the video
 
Highlight search results