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
|
|
|
namespace aik099\PHPUnit\BrowserConfiguration; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use aik099\PHPUnit\APIClient\BrowserStackAPIClient; |
15
|
|
|
use aik099\PHPUnit\APIClient\IAPIClient; |
16
|
|
|
use aik099\PHPUnit\Event\TestEvent; |
17
|
|
|
use WebDriver\ServiceFactory; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Browser configuration tailored to use with "BrowserStack" service. |
21
|
|
|
* |
22
|
|
|
* @link https://www.browserstack.com/automate |
23
|
|
|
*/ |
24
|
|
|
class BrowserStackBrowserConfiguration extends ApiBrowserConfiguration |
25
|
|
|
{ |
26
|
|
|
const TYPE = 'browserstack'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Returns API class for service interaction. |
30
|
|
|
* |
31
|
|
|
* @return IAPIClient |
32
|
|
|
*/ |
33
|
1 |
|
public function getAPIClient() |
34
|
|
|
{ |
35
|
1 |
|
return new BrowserStackAPIClient( |
36
|
1 |
|
$this->getApiUsername(), |
37
|
1 |
|
$this->getApiKey(), |
38
|
1 |
|
ServiceFactory::getInstance()->getService('service.curl') |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Hook, called from "BrowserTestCase::setUp" method. |
44
|
|
|
* |
45
|
|
|
* @param TestEvent $event Test event. |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
9 |
|
public function onTestSetup(TestEvent $event) |
50
|
|
|
{ |
51
|
9 |
|
if ( !$event->validateSubscriber($this->getTestCase()) ) { |
52
|
1 |
|
return; |
53
|
|
|
} |
54
|
|
|
|
55
|
9 |
|
parent::onTestSetup($event); |
56
|
|
|
|
57
|
9 |
|
$desired_capabilities = $this->getDesiredCapabilities(); |
58
|
|
|
|
59
|
9 |
|
if ( getenv('PHPUNIT_MINK_TUNNEL_ID') ) { |
60
|
1 |
|
$desired_capabilities['browserstack.local'] = 'true'; |
61
|
1 |
|
$desired_capabilities['browserstack.localIdentifier'] = getenv('PHPUNIT_MINK_TUNNEL_ID'); |
62
|
|
|
} |
63
|
|
|
|
64
|
9 |
|
$this->setDesiredCapabilities($desired_capabilities); |
65
|
9 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Returns hostname from browser configuration. |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
7 |
|
public function getHost() |
73
|
|
|
{ |
74
|
7 |
|
return $this->getApiUsername() . ':' . $this->getApiKey() . '@hub.browserstack.com'; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns desired capabilities from browser configuration. |
79
|
|
|
* |
80
|
|
|
* @return array |
81
|
|
|
* @link http://www.browserstack.com/automate/capabilities |
82
|
|
|
*/ |
83
|
12 |
|
public function getDesiredCapabilities() |
84
|
|
|
{ |
85
|
12 |
|
$capabilities = parent::getDesiredCapabilities(); |
86
|
|
|
|
87
|
12 |
|
if ( !isset($capabilities['os']) ) { |
88
|
10 |
|
$capabilities['os'] = 'Windows'; |
89
|
10 |
|
$capabilities['os_version'] = '7'; |
90
|
|
|
} |
91
|
|
|
|
92
|
12 |
|
if ( !isset($capabilities['acceptSslCerts']) ) { |
93
|
10 |
|
$capabilities['acceptSslCerts'] = 'true'; |
94
|
|
|
} |
95
|
|
|
|
96
|
12 |
|
return $capabilities; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|