WebDrive – Selenium 2 WebDriver support for Play framework
Written by Raghu Kaippully
WebDrive module provides Selenium 2 testing support for Play framework. You can use this module to test your application with any browsers supported by Selenium WebDriver.
Motivation
Play framework lets you write tests with Selenium. The tests can be automatically run with the play auto-test
command. The selenium tests are run using HtmlUnit. While this works great for simple web pages it may not be suited for all – especially with complex JavaScript. Besides, you may want to test the pages using multiple browsers.
WebDrive lets you run your existing selenium tests on browsers of your choice. You save selenium tests under the tests
directory with a .test.html
extension as mentioned in Play documentation. WebDrive can run these tests on any of the supported browsers.
Installation
- Use the standard Play module installation command:
play install webdrive 0.2
- Add the dependency to your project:
require:
- play -> webdrive 0.2:
transitive: false
WebDrive has a lot of dependencies and we don’t want those jars to be copied over to the application’s lib directory. That is why we specified transitive: false
.
- Run
play dependencies --sync
Usage
In application.conf
you mention the list of browsers to run tests on:
webdrive.classes=ie,chrome,firefox
Below is a list of all supported driver names:
Name | WebDriver class |
---|---|
htmlunit | org.openqa.selenium.htmlunit.HtmlUnitDriver |
andriod | org.openqa.selenium.android.AndroidDriver |
chrome | org.openqa.selenium.chrome.ChromeDriver |
firefox | org.openqa.selenium.firefox.FirefoxDriver |
ie | org.openqa.selenium.ie.InternetExplorerDriver |
iphone | org.openqa.selenium.iphone.IPhoneDriver |
You can use the fully qualified class name instead of the simple names if you wish.
Optionally, you may also specify number of seconds WebDrive waits for each test before marking it as ERROR
:
webdrive.timeout=300
If you do not specify any value WebDrive uses a default value of 120 seconds.
Tests are run using the command:
play webdrive:test
Test results are available under test-result
folder. Results for each browser driver will be stored in separate folders inside test-result
. If a test fails, a file named result.failed
will be created in the folder for that driver and also in test-result
folder. If all tests pass, a file named result.passed
will be created instead. You can also check the return code of the command to check whether the tests ran successfully.
Project Information
Source code: https://github.com/rkaippully/play-webdrive
Issue tracking: https://github.com/rkaippully/play-webdrive/issues