Browser Aliases¶
All previous examples demonstrate various ways how browser configuration can be defined, but they all have same downside - server connection details stay hard-coded in test case classes. This could become very problematic if:
- same test cases needs to be executed on different servers (e.g. each developer runs them on his own machine)
- due change in server connection details each test case class needs to be changed
To solve this problem a browser aliases were introduced. Basically a browser alias is predefined browser configuration, that is available in the test case by it’s alias. Here is how it can be used:
- create base test case class, by extending
BrowserTestCase
class in the project withgetBrowserAliases
method in it - the
getBrowserAliases
method will return an associative array of a browser configurations (array key acts as alias name) - in any place, where browser configuration is defined use
'alias' => 'alias_name_here'
instead of actual browser configuration - feel free to override any part of configuration defined in alias
Note
Nested aliases are also supported.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <?php
use aik099\PHPUnit\BrowserTestCase;
abstract class BrowserAliasTestCase extends BrowserTestCase
{
public function getBrowserAliases()
{
return array(
'example_alias' => array(
'driver' => 'selenium2',
'host' => 'localhost',
'port' => 4444,
'browserName' => 'firefox',
'baseUrl' => 'http://www.google.com',
),
);
}
}
class ConcreteTest extends BrowserAliasTestCase
{
public static $browsers = array(
array(
'alias' => 'example_alias',
),
array(
'alias' => 'example_alias',
'browserName' => 'chrome',
),
);
}
|