|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the phpunit-mink library. |
|
4
|
|
|
* For the full copyright and license information, please view |
|
5
|
|
|
* the LICENSE file that was distributed with this source code. |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
|
8
|
|
|
* @link https://github.com/aik099/phpunit-mink |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace aik099\PHPUnit\MinkDriver; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
use aik099\PHPUnit\BrowserConfiguration\BrowserConfiguration; |
|
16
|
|
|
use Behat\Mink\Driver\DriverInterface; |
|
17
|
|
|
|
|
18
|
|
|
class Selenium2DriverFactory implements IMinkDriverFactory |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Returns driver name, that can be used in browser configuration. |
|
23
|
|
|
* |
|
24
|
|
|
* @return string |
|
25
|
|
|
*/ |
|
26
|
10 |
|
public function getDriverName() |
|
27
|
|
|
{ |
|
28
|
10 |
|
return 'selenium2'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Returns default values for browser configuration. |
|
33
|
|
|
* |
|
34
|
|
|
* @return array |
|
35
|
|
|
*/ |
|
36
|
10 |
|
public function getDriverDefaults() |
|
37
|
|
|
{ |
|
38
|
|
|
return array( |
|
39
|
10 |
|
'port' => 4444, |
|
40
|
|
|
'driverOptions' => array(), |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Returns a new driver instance according to the browser configuration. |
|
46
|
|
|
* |
|
47
|
|
|
* @param BrowserConfiguration $browser The browser configuration. |
|
48
|
|
|
* |
|
49
|
|
|
* @return DriverInterface |
|
50
|
|
|
* @throws \RuntimeException When driver isn't installed. |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public function createDriver(BrowserConfiguration $browser) |
|
53
|
|
|
{ |
|
54
|
1 |
|
if ( !class_exists('Behat\Mink\Driver\Selenium2Driver') ) { |
|
55
|
|
|
throw new \RuntimeException( |
|
56
|
|
|
'Install MinkSelenium2Driver in order to use selenium2 driver.' |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
$browser_name = $browser->getBrowserName(); |
|
61
|
1 |
|
$capabilities = $browser->getDesiredCapabilities(); |
|
62
|
1 |
|
$capabilities['browserName'] = $browser_name; |
|
63
|
|
|
|
|
64
|
|
|
// TODO: Maybe doesn't work! |
|
65
|
1 |
|
ini_set('default_socket_timeout', $browser->getTimeout()); |
|
66
|
|
|
|
|
67
|
1 |
|
$driver = new \Behat\Mink\Driver\Selenium2Driver( |
|
68
|
1 |
|
$browser_name, |
|
69
|
1 |
|
$capabilities, |
|
70
|
1 |
|
'http://' . $browser->getHost() . ':' . $browser->getPort() . '/wd/hub' |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
1 |
|
return $driver; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|