Control Virtual Service Execution

Applies to ReadyAPI 3.56, last modified on November 21, 2024

Groovy scripts can improve your control over simulated web services.

Where to use

You can run the scripts in the ways below:

  • As a setup or teardown script on the test case, test suite or project level in functional tests.

Examples

Starting and Stopping Virtual Services

ReadyAPI provides the Virtual Service Runner test step that you can use to start or stop virtual services in your functional tests. However, if your test is complex and runs multiple test cases in parallel, you may want to use Setup and Teardown scripts instead to control your virtual services.

  • The following script starts the specified virtual service:

    Groovy

    // Start the virtual service
    virtRunner.run('VirtName')

    Tip: You do not need to check if the virtual service is running manually. ReadyAPI will automatically check this and perform no actions if it is running.
  • The following script stops the specified virtual service:

    Groovy

    // Stop the virtual service
    virtRunner.stop('VirtName')

Simulate a Delay in SOAP Virtual Responses

To simulate a delay between 0 and 10 seconds in the SOAP service response, add the "MockRunListener.onMockResult" event at the project level with the following code:

Groovy

sleep(new Random().nextInt(10) * 1000)

This method only works for SOAP virtual services. To simulate a delay in REST virtual services, use virtual service scripts.

See Also

Testing with Virtual Services
Creating Your First Virtual Service
Scripting

Highlight search results