Getting Started
Below you’ll find all the needed information to find your way across the library.
Installation
The library can be installed using Composer like so:
define the dependencies in your
composer.json
:
{
"require": {
"aik099/phpunit-mink": "~2.0"
}
}
install/update your vendors:
$ curl http://getcomposer.org/installer | php
$ php composer.phar install
Basic Usage
sub-class the test case class from the
\aik099\PHPUnit\BrowserTestCase
class (line 5)define used browser configurations in the static
$browsers
property of that class (line 8-16)access the Mink session by calling the
$this->getSession()
method in your test (line 21)access browser configuration by calling the
$this->getBrowser()
method in your test (line 35)
1<?php
2
3use aik099\PHPUnit\BrowserTestCase;
4
5class GeneralTest extends BrowserTestCase
6{
7
8 public static $browsers = array(
9 array(
10 'driver' => 'selenium2',
11 'host' => 'localhost',
12 'port' => 4444,
13 'browserName' => 'firefox',
14 'baseUrl' => 'http://www.google.com',
15 ),
16 );
17
18 public function testUsingSession()
19 {
20 // This is Mink's Session.
21 $session = $this->getSession();
22
23 // Go to a page.
24 $session->visit('http://www.google.com');
25
26 // Validate text presence on a page.
27 $this->assertTrue($session->getPage()->hasContent('Google'));
28 }
29
30 public function testUsingBrowser()
31 {
32 // Prints the name of used browser.
33 echo sprintf(
34 "I'm executed using '%s' browser",
35 $this->getBrowser()->getBrowserName()
36 );
37 }
38
39}
Selenium in the Cloud
When using Selenium-based solution for the automated testing in the cloud (e.g. Sauce Labs or BrowserStack) you’ll need to specify the following settings:
'type' => 'saucelabs'
or'type' => 'browserstack'
'apiUsername' => '...'
'apiKey' => '...'
instead of the host
and port
settings. In all other aspects everything will work the same as if all
tests were running locally.
1<?php
2
3use aik099\PHPUnit\BrowserTestCase;
4
5class BrowserConfigExampleTest extends BrowserTestCase
6{
7
8 public static $browsers = array(
9 // Sauce Labs browser configuration.
10 array(
11 'type' => 'saucelabs',
12 'apiUsername' => '...',
13 'apiKey' => '...',
14 'browserName' => 'firefox',
15 'baseUrl' => 'http://www.google.com',
16 ),
17
18 // BrowserStack browser configuration.
19 array(
20 'type' => 'browserstack',
21 'apiUsername' => '...',
22 'apiKey' => '...',
23 'browserName' => 'firefox',
24 'baseUrl' => 'http://www.google.com',
25 ),
26
27 // Regular browser configuration.
28 array(
29 'driver' => 'selenium2',
30 'host' => 'localhost',
31 'port' => 4444,
32 'browserName' => 'chrome',
33 'baseUrl' => 'http://www.google.com',
34 ),
35 );
36
37}
Continuous Integration
When the website under test isn’t publicly accessible, then:
secure tunnel needs to be created from the website under test to the server, that runs the tests
the created tunnel identifier needs to specified in the
PHPUNIT_MINK_TUNNEL_ID
environment variable
Note
Before v2.1.0 the environment variable was called TRAVIS_JOB_NUMBER
.