Groovy scripts can improve your control over simulated web services.
You can run the scripts in the ways below:
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
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 ServiceV scripts.|