REST VirtResponse Test Step

Applies to ReadyAPI 3.52, last modified on April 18, 2024

About REST VirtResponse test step

The REST VirtResponse test step listens to a specified REST request and returns a preconfigured response.

When the execution of a test case reaches the REST VirtResponse test step, the test case run pauses and waits for a request to the specified resource on the configured port with the specified method. Once a request is received, REST VirtResponse returns the result, and the test runner goes to the next step in the test case.

Such temporary virtual services can catch requests sent by webhooks. This way, you can quickly set up a temporary service to catch a single request, or make this a part of the test without setting up an application or a separate virtual API to handle the requests.

Requirements

To use this test step, you need a ReadyAPI Test license. If you do not have it, you can request it on our web site or start a trial.

Creating REST VirtResponse test step

  • You can add a REST VirtResponse test step as a usual test step.

– or –

  • On the Projects page, right-click the desired REST request and select Add as REST VirtResponse Step.

  • Select a test case, to which you want to add the test step.

When you add a REST VirtResponse test step to your test case, ReadyAPI shows you a dialog where you can customize the test step as you need.

New VirtResponse Step dialog

The dialog contains the following options:

  • Name – The name of the created step.

  • Port – Specifies the port to listen on.

  • Service – Specifies the service the test step should mock.

  • Resource – Specifies what resource of the specified service to mock.

  • Method – Specifies the method that the test step should mock.

After you click OK, ReadyAPI creates the test step and shows its editor.

Editing REST VirtResponse test step

You can modify settings of the test step in its editor:

REST VirtResponse test step editor

Click the image to enlarge it.

The REST VirtResponse test step editor is similar to the REST Request test step editor.

The Request editor allows you to examine the request’s endpoint and raw data. You can also specify the method that the test step is mocking.

The Response editor allows you to customize the response itself.

  • HTTP Status Code – Specifies the code of the response.

  • Content | Media Type – Specifies the content type of the response.

In the Editor panel, you can modify the response content. The Raw panel shows you the raw data of the last sent response.

The Header tab allows you to add and modify custom headers for the response.

In the Assertions panel, add assertions for the test step.

Property list

Besides the test step editor, you can adjust test step behavior by using its properties in the Properties and Custom REST VirtResponse Test Step Properties panels in the Navigator.

Name Description
Name

The test step’s name.

Description

Text description of the test step.

Port

The port that the test step is listening on.

Note: This port number is used for HTTP requests only. For HTTPS requests, it must differ from the Virtual service port value in the Preferences > SSL setting. See below.
Path

The path the test step is listening on.

Timeout

The timeout for the test step in milliseconds. If no request has been received within the specified time period, the test step will fail. If this property is 0, it is ignored.

Start Step

The test step from which the REST VirtResponse starts waiting for a request. It can be useful when you use a request and response in the same test case. If you do not specify this property, the test step starts listening when the step is executed.

Values in the Custom REST VirtResponse Test Step Properties tab are available to other test steps in your project. For example, you can verify these property values with the Assertion test step, or check them and change the execution flow with the Conditional GoTo test step. To learn more, see About Properties.

This tab contains the following properties that provide access to the request and response data:

Name Description
Response

The response data without headers. You can see the same content in the response Editor panel. Property expansions are represented without converting them to expected values.

Request

Data of the request without headers.

Verifying response

You can add and manage assertions in the same way as in the SOAP Request test step editor.

To add, change or modify them, use the Assertion panel. You can use the following assertions:

Name Description
Property Content:
Contains Verifies that the request contains the specified string.
Message Content Assertion Verifies that the message contains expected contents.
Not Contains Verifies that the request does not contain the specified value
XPath Match Checks whether the result of the specified XPath expression is equal to the specified value.
XQuery Match Verifies that the result of the specified XQuery expression is equal to the specified value.
Compliance, Status and Standards
HTTP Header Equals Checks whether the request contains the expected value of an HTTP header.
HTTP Header Exists Verifies that the request contains the specified HTTP header.
Script
Script Assertion Executes a script to perform a custom assertion.

Logging

If the test step is run as part of a test case, you can see a more detailed log in the Transaction Log panel.

Notes

  • If you want to use the REST Request test step to send a request to the REST VirtResponse test step, place the two test steps in different test cases. Otherwise, test execution will pause on the REST VirtResponse test step and will never reach the REST Request test step.

  • You can use Property Transfers with REST VirtResponse test steps just as with REST requests, that is, properties can be transferred from incoming requests and to outgoing responses.

  • Although running a load test containing REST VirtResponse steps will work, these steps are not designed for load testing, and may cause significant overhead. In load tests, you can create a virtual service for your REST service by using virtualization.

Working with

Below, you can find information on common tasks that you can perform with the REST VirtResponse test step.

To configure the REST VirtResponse test step to listen for HTTPS requests:

  • Open the REST Request test step that will simulate the HTTPS request and check the port number used there.

  • Open the Preferences > SSL options menu.

  • Modify the settings:

    • Select the Enable virtual service SSL check box.

    • Edit the Virtual service port setting.

      This port must –

      • Be the same as the port you specified in the REST Request properties, and

      • Be different from the port specified in the VirtReponse test step properties (see below).

    • Specify the Virtual service KeyStore and Virtual service password properties.

    • Save the changes.

  • Open your REST VirtResponse test step for editing, and change its Port property. Set any port that is available on your computer and that is different from the port you specified in the Preferences > SSL settings.

    When VirtResponse is waiting for an HTTPS request, it does not check the Port property value. It listens on the host and path specified by the test step properties and uses the port number specified by the Preferences > SSL settings.

See Also

Test Steps
SOAP VirtResponse Test Step
REST Request Test Step
About Virtualization in ReadyAPI

Highlight search results