In ReadyAPI, you can use scripts to enhance tests and extend the ReadyAPI functionality. You can also create your own modules and reuse them in multiple projects.
Most commonly, scripts are used to prepare your environment before running a test and remove any aftereffects of the test when it finishes. For example, you can start virtual services before starting your test and stop them once the testing is over.
Scripts are available across ReadyAPI and can happen in many different cases:
Groovy Script test steps run as part of the functional test.
Setup and TearDown scripts run when you start or stop the related test item.
Report scripts run whenever the test generates a report.
Groovy Script data sources extracting and passing data as specified in code.
Virtual service Start, Stop, OnRequest, and AfterRequest scripts.
ReadyAPI events that provide additional flexibility in managing scripts and their triggers.
Common scripting tasks
Here are some common ways to improve tests by using scripts:
Create Groovy Script test steps to add various enhancements to a functional test case.
Create script assertions for REST, GraphQL, or SOAP responses.
Enable the setup and teardown scripts to use them during the initialization and cleanup on the project, test case, or test suite level, or in load tests.
Enable the startup, shutdown, Before Request, and After Request scripts to perform initialization, cleanup, or dispatch and handle requests to the virtual API.
Store scripts common for your projects in Groovy Script libraries and reuse them whenever you want.
Generate data for test cases with data source scripts.
Save the test case run data with data sink scripts.
Generate property values dynamically with DataGen script properties.
You can find some examples of script usage in the Groovy Scripting Samples section.
Currently, ReadyAPI supports the following languages:
Libraries and script collections
Scripting editors in ReadyAPI give you access to several types of scripting objects:
Libraries that come pre-installed with ReadyAPI, including a number of standard Groovy and Java classes.
External Java libraries that you can add if the pre-installed libraries do not satisfy your needs.
Custom collections of Groovy scripts that you can create and reuse throughout your projects.
To learn more about customizing your scripting needs, see the Script Libraries section.
|ReadyAPI uses a number of third-party libraries. It is quite possible that we will update some of these libraries or even remove them from ReadyAPI. If you use classes from these libraries, you will have to update your scripts. See a list of third-party libraries updated in ReadyAPI 3.10.1.|
Scripting also allows you to access objects of ReadyAPI itself. For a reference to the internal structure of ReadyAPI, see API docs.
Each scripting editor has its own set of objects imported by default. You can learn more about them in the respective topics:
ReadyAPI script editors support code completion for Groovy. As you type code, available methods and parameters will appear in a drop-down list, so you can select them and speed up the code writing.
Scripting editors also offer code validation and code templates. You can also use property expansions to insert data from other test steps into your scripts.
For details about editor features, see Script Editors.
You can find examples of how to perform certain tasks using scripts in this section:Groovy Scripting Samples