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 when:
the same test cases needs to be executed on the different servers (e.g. each developer runs them on his own machine)
due change in the 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 a 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 itthe
getBrowserAliases
method will return an associative array of a browser configurations (array key acts as an alias name)in any place, where browser configuration is defined use
'alias' => 'alias_name_here'
instead of actual browser configurationfeel free to override any part of the configuration defined in the alias
Note
Nested aliases are also supported.
1<?php
2
3use aik099\PHPUnit\BrowserTestCase;
4
5abstract class BrowserAliasTestCase extends BrowserTestCase
6{
7
8 public function getBrowserAliases()
9 {
10 return array(
11 'example_alias' => array(
12 'driver' => 'selenium2',
13 'host' => 'localhost',
14 'port' => 4444,
15 'browserName' => 'firefox',
16 'baseUrl' => 'http://www.google.com',
17 ),
18 );
19 }
20
21}
22
23
24class ConcreteTest extends BrowserAliasTestCase
25{
26
27 public static $browsers = array(
28 array(
29 'alias' => 'example_alias',
30 ),
31 array(
32 'alias' => 'example_alias',
33 'browserName' => 'chrome',
34 ),
35 );
36}