Selenium tests are often written by using Java. Since Groovy has syntax similar to Java, these tests can be moved to ReadyAPI with minor adjustments.
So, to move your JUnit Selenium test to ReadyAPI, you can copy the code and paste it to the Groovy Script test step.
Some Java features are not supported by Groovy, and parts of your code may behave in a different manner after the transition, or your test may fail to start.
Important
If you use Maven dependencies to include JUnit libraries in your project, you need to manually copy them to the <ReadyAPI installation>/bin/ext
directory.
You can find the full list of differences between Groovy and Java in the Groovy documentation.
Another thing you may want to do after moving to ReadyAPI is to improve the style. Groovy is very forgiving in terms of style. For example, you do not need to end the line with semicolons.
Suppose, you have the following JUnit test that uses Selenium:
To use JUnit and Selenium classes in a Groovy script, you need to add their libraries to ReadyAPI.
Copy Selenium libraries as described in Requirements for Running Selenium Tests.
Download the junit.jar file from the following page:
Copy the downloaded file to the
<ReadyAPI installation>/bin/ext
directory.
Add the Groovy test step to your test and open it.
Paste your Java code to the created test step:
Most likely, your code will not work as expected, so you need to modify it.
Selenium searches for the Gecko driver in the webdriver.gecko.driver
system property. You need to specify the driver location in one of the following ways:
Add the
-Dwebdriver.gecko.driver=<path to gecko driver>
variable to the list of JVM options. See Modifying JVM Settings to learn how to do this.Set the system property value in the Groovy test step:
To make the best use of JUnit tests in ReadyAPI, run them by using the JUnit test runner.
To run our sample test, we need to add the following code to the Groovy test step:
If we run our test now, it will pass, whatever the JUnit test results are. To fix that, we need to add the assert
command that marks the test step as failed and posts an error message.
Below is the complete code of the Groovy Script test step: