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.
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:
// Start the virtual service
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:
// Stop the virtual service
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:
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.|