Selenium is a portable software testing framework for web applications.
It has a suite of tools that are useful for testing automation. Single test scripts can be recorded and played back using Selenium IDE. More complex tests can be written on various programming languages and executed using Selenium Remote Control. In addition, tests executions can be distributed using Selenium Grid.
Currently, we use four of Selenium programs: The code we write communicates with the Remove Control Server, that might be in another computer. And the Remote Server makes Selenium Core instances to execute the specific actions on a web browser. We use Selenium Grid to parallelize the execution through a hub that communicates multiple Remote Controllers with a Selenium Server. Finally the IDE is used to get a clue of how user actions can be expressed in terms that selenium can interpret.
It can be downloaded at their website. Once installed, open it from the menu Tools->Selenium IDE of your Firefox browser.
The red button is used to record the actions performed on the browser. While you press buttons, select options and enter text, those actions are recorded and are stored as a table. You can run the pre-recorded actions from the same IDE with the green play button.
<tr> <td>open</td> <td>/openbravo/security/Login_FS.html</td> <td></td> </tr> <tr> <td>type</td> <td>user</td> <td>Openbravo</td> </tr> <tr> <td>type</td> <td>password</td> <td>openbravo</td> </tr> <tr> <td>clickAndWait</td> <td>buttonOK</td> <td></td> </tr>
In addition, Selenium IDE can be used to translate from HTML to one of the languages supported by the Remote Control.
However this is not the same code that we will use in our testing repository because:
- Recorded code is hard to maintain and is failure prone.
- There is no chance to reuse code because all tests are done from scratch, and the IDE doesn't factorize common actions so there would be a lot of duplicated code.
- All the parameters are hardcoded.
Even though, this IDE is useful because it gives us a clear understanding of what we will have to write.
Selenium Remote Control
It can be downloaded from their website . This file includes the server and client libraries for Java, C#, Perl, PHP, Python and Ruby.
With Openbravo ERP we use the Java client driver to automate our integration tests, because it's the language of the ERP and most developers are confortable with it. Previous HTML example of the login process will look like this using Java:
selenium.open("openbravo/security/Login_FS.html"); selenium.type("user", "Openbravo"); selenium.type("password", "openbravo"); selenium.click("buttonOK"); selenium.waitForPageToLoad("30000");
In order to execute the test, we need to start selenium server first:
java -jar /path/to/selenium-server.jar -multiWindow
Note: -multiWindow option is required to run the test in a separate browser window. If this parameter is not used, selenium runs in a subframe; that doesn't work with Openbravo ERP
java -classpath .:/path/to/junit-4.5.jar:/path/to/selenium-java-client-driver.jar org.junit.runner.JUnitCore Login
Note: Even though Selenium tests can be run without a testing framework, we have found some advantages while using Junit
Selenium Grid allows the parallel execution of Selenium tests.
First the Selenium hub has to be started. And then one or more Selenium remote controllers can be registered as executors with that hub.
Of course, something will have to run tests in parallel. We use the Ant parallel tasks for this.
And when the Hub receives the requests it will send them to a idle Remote Controller (if any) or queue them.