Resources »

Guides »

Developers »

Build a test environment with WebDriver automation


Cerb provides a WebDriver test suite that automatically builds a clean test environment by remote controlling a web browser. This verifies that Cerb functions as expected and creates realistic sample data for testers, developers, and evaluators.

You must run the WebDriver tests in a development environment on a fresh copy of Cerb.

Create a development environment

Clone a copy of Cerb from GitHub

git clone cerb_test

cd cerb_test

Create a new database

Log into MySQL as an administrator and create a new database and user:

GRANT ALL PRIVILEGES ON cerb_test.* TO cerb@localhost IDENTIFIED BY 's3cr3t';

Configure the database connection

Edit the framework.config.php file and configure the database connection:


Start PHP’s built-in web server

php -S localhost:8080

Prepare the test suite

cd tests

Install Composer

Run the following command to see if Composer is already installed:

	composer --version

If the command isn’t found, follow these instructions to install Composer:

Run Composer

Once Composer is installed, you can install the required dependencies like PHPUnit:

	composer install

Run the platform unit tests

At this point you should run the platform unit tests to make sure everything is working properly.

vendor/bin/phpunit -c phpunit.cerb.platform.xml 

You should see output like:

PHPUnit 5.7.21 by Sebastian Bergmann and contributors.

.............................................                     52 / 52 (100%)

Time: 122 ms, Memory: 12.00MB

OK (52 tests, 263 assertions)

This means that Cerb is ready to install on your server.

Run the database installation tests

Test the installation process by populating the new Cerb database:

vendor/bin/phpunit -c phpunit.cerb.install.xml

You should see output like:

PHPUnit 5.7.21 by Sebastian Bergmann and contributors.

.....                                                               5 / 5 (100%)

Time: 4.85 seconds, Memory: 14.00MB

This means that no issues were encountered while running the installer and creating Cerb’s database schema.

Run the WebDriver tests

Now we’ll configure the WebDriver tests to automatically create sample data using Cerb’s web interface.

Configure WebDriver

Edit the bootstrap.eval.php file.

The defaults will work for the steps above, but if you need to make changes these are the two important lines:

// The URL to Selenium's WebDriver API
define('WEBDRIVER_URL', 'http://localhost:4444/wd/hub');

// The URL where you installed Cerb
define('BROWSER_URL', 'http://localhost:8080/index.php');

By default, WebDriver will attempt to run the tests in the Chrome browser. You can choose a different browser by uncommenting only one of these lines:

// Pick one:
//$capabilities = DesiredCapabilities::phantomjs();
//$capabilities = DesiredCapabilities::safari();
//$capabilities = DesiredCapabilities::firefox();
$capabilities = DesiredCapabilities::chrome();

Start Selenium

Start the Selenium Server:


This is where WebDriver will connect to remote control your web browser.

Run the WebDriver tests

Now we’re ready for the automation to begin. Run the WebDriver unit tests:

vendor/bin/phpunit -c phpunit.cerb.eval.xml 

You should see a web browser start up and automatically perform a series of actions.

At the end, you should have output like:

PHPUnit 5.7.21 by Sebastian Bergmann and contributors.

..................................................                50 / 50 (100%)

Time: 2.36 minutes, Memory: 9.06MB

OK (50 tests, 88 assertions)

Your sample database has been created.

You can shut down the Selenium Server by pressing <CTRL> + C.

Log in to your new test instance

Now you can log in to your new Cerb instance to begin your testing.

Navigate to: http://localhost:8080/index.php/login/

The following accounts are available:

Email Password
kina@cerb.example (admin) cerb
milo@cerb.example cerb
janey@cerb.example cerb
karl@cerb.example cerb
mara@cerb.example cerb
ned@cerb.example cerb

Finishing up

You can import additional packages based on your needs.