ReadyAPI is shipped with a number of Java and Groovy libraries that you can use in your scripts right away. Some of the libraries are imported in all the editors by default; others have to be imported first.
Libraries imported by default
A number of basic Java and Groovy classes are imported by default and ready to be used in all the scripting editors in ReadyAPI. These are:
Libraries ready for import
There are more libraries that are shipped with ReadyAPI but not imported to the scripting editors by default. You can import them by using the
import <library name> command. Here are some of the libraries:
java.nio.*– Used for low-level I/O operations.
javax.jms.*– A common way to work with JMS.
groovy.json.*– Used for parsing and producing JSONs.
groovy.xml.*– Used for parsing and producing XMLs.
groovy.sql.*– Used for working with JDBC.
org.apache.activemq.*– Used for actions with ActiveMQ JMS.
org.apache.commons.*– Contains many reusable Java components.
org.apache.http.*– Used for working with HTTP.
Here is a simple example of a script that uses ready-for-import libraries to copy a file. You can run it in the Groovy Script test step editor:
//Import libraries for working with files
//Create objects for the copied file and the target file
Path source = Paths.get("C:\\Users\\elle.stevenson\\Desktop\\test.xlsx");
Path target = Paths.get("C:\\Users\\elle.stevenson\\Desktop\\out\\copied.xlsx");
//Copy the file