To run Selenium tests from ReadyAPI, you need to use the Groovy Script test step. The Groovy language allows you to import Selenium WebDriver and work with it.
Important
You need to copy all Selenium WebDriver files to the ReadyAPI folder. For more information, see Requirements for Running Selenium Tests.
This example uses a virtual service from the REST Sample Project shipped with ReadyAPI.
The example requires the Mozilla Firefox web browser. You need to have it installed on your computer to be able to run the test.
To run the Selenium test from Groovy script, first, you need to import the needed WebDriver.
For example, you can use the following code to import the driver for Firefox:
You will also need to import packages that you will use in the code. For example:
To run tests in Firefox in Selenium 3 and later:
Download the Gecko driver.
Place it somewhere within the ReadyAPI installation folder – for example, in
<ReadyAPI installation>/bin/ext
.Add the system property for the Gecko driver within the code:
After that, define the driver in code.
Now, you can work with Selenium WebDriver. For example, the following code starts the browser, opens the ReadyAPI documentation and searches for Groovy.
While testing, you can post information to the log by using the log
object.
To post an informative message, use the
log.info
method.To post a warning, use the
log.warn
method.To post an error, use the
log.error
orlog.fatal
method.
After the test performs all the needed actions, close Selenium WebDriver.
Here is a simple Groovy script that uses Selenium: