Skip to content

Use Sauce Labs with the PHPUnit Selenium 2 Driver

Sauce Labs is providing a cloud for Selenium tests. Each free account comes with
200 minutes of free testing per month. This is very useful if you want to assure some
basic functionallity of your website without having to set up your own Selenium Grid.

In order to use your existing PHPUnit Selenium2 test-cases, all you need to do is go
to saucelabs.com and create an account. Go to the your account page get your API key.

For your tests simply use their host and port 80.

require_once 'PHPUnit/Extensions/Selenium2TestCase.php';
classGUITest extends \PHPUnit_Extensions_Selenium2TestCase {
public function __construct() {
$user = '[your api key]';
$token = '[your api token]';
$this->setHost("$user:[email protected]");
$this->setPort(80);
}
protected function setUp() {
$this->setBrowser('firefox');
$this->setBrowserUrl('http://[your link]/');
}
public function testLoginLinkOnStartpage() {
$this->url('http://[your link]/');
$link = $this->byId('link-login');
$link->click();
$this->assertEquals('Anmelden', $this->title());
}
}

Examples on now to write more tests are available in the unit test of the Selenium2 unit test.

Run your test as usual using phpunit.
You can see all your created jobs in the Sauce Labs dashboard. They even provide video recordings of all tests.

© 2020 by Adrian Philipp