With Selenium, you can use the PHP Bindings to easily create browser automation tests. Using CrossBrowserTesting, you can automate all of your PHP test scripts against our huge collection of browsers and devices. To learn more about the Selenium API, we recommend you read Selenium’s documentation which can be found here.
To get started, we’ll need Composer in order to gather the necessary dependencies for our test. You can find download instructions for Composer here. Once we have Composer in place, we need to add the following libraries:
php composer.phar facebook/webdriver
php composer.phar phpunit/phpunit
php composer.phar rmccue/requests
Setting up Our Test
We’ll be setting our test up as a PHPUnit TestCase. This allows us to make assertions about our webpage as we go along. We’ll be using a basic Angular ToDo app to use as our test case. Copy the following code into your favorite text editor, and be sure to change the username and authorization key to your email address for CrossBrowserTesting and the private key found on the Manage Account section of our app.
Once we have our script setup, we can quickly run the test and see our results using phpunit. Run your test by executing the following command:
Jump over to our app, and you should see the test being executed on Windows 10 and Firefox 46. If our test case passes, we should see the following output from PHPUnit:
OK (1 test, 3 assertions)
CrossBrowserTesting allows you to add certain capabilities to your test, like video recordings, naming structure and more.
Naming your tests can help organize your automated test cases for easier debugging. You can also mark Build number to denote releases.
$capabilities = array("name"=> "Selenium Test Example");
$capabilities = array("build"=> "1");
To choose your environment, you can select from Browsers, Operating System, Resolutions, and Devices. You can use our easy Selenium Wizard to select your configuration or hit our browser list endpoint.
For superior debugging capabilities, CrossBrowserTesting offers the ability to record a video of your Selenium test session. You can find a copy of your test results here.
$capabilities = array("record_video"=> "true");
To record the network packets during your test for performance debugging, set the following to “true”.
$capabilities = array("record_network"=> "true");
Running A Local Test
With our Local Tunnel, you can run a test on a local URL or behind your company’s firewall. There are two different ways to connect the CrossBrowserTesting local tunnel: our NodeJS client and our Chrome Extension.
You can read more about setting up, starting, and using your tunnel connection here.
When a tunnel is open, any automated test can access websites locally, behind a firewall, or across a proxy. There is no need to set a capability during your test.