|
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\IAPIClient; |
|
15
|
|
|
use aik099\PHPUnit\APIClient\SauceLabsAPIClient; |
|
16
|
|
|
use aik099\PHPUnit\Event\TestEvent; |
|
17
|
|
|
use WebDriver\SauceLabs\SauceRest; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Browser configuration tailored to use with "Sauce Labs" service. |
|
21
|
|
|
* |
|
22
|
|
|
* @link https://saucelabs.com/php |
|
23
|
|
|
*/ |
|
24
|
|
|
class SauceLabsBrowserConfiguration extends ApiBrowserConfiguration |
|
25
|
|
|
{ |
|
26
|
|
|
const TYPE = 'saucelabs'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Returns API class for service interaction. |
|
30
|
|
|
* |
|
31
|
|
|
* @return IAPIClient |
|
32
|
|
|
*/ |
|
33
|
1 |
|
public function getAPIClient() |
|
34
|
|
|
{ |
|
35
|
1 |
|
$sauce_rest = new SauceRest($this->getApiUsername(), $this->getApiKey()); |
|
36
|
|
|
|
|
37
|
1 |
|
return new SauceLabsAPIClient($sauce_rest); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Hook, called from "BrowserTestCase::setUp" method. |
|
42
|
|
|
* |
|
43
|
|
|
* @param TestEvent $event Test event. |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
8 |
|
public function onTestSetup(TestEvent $event) |
|
48
|
|
|
{ |
|
49
|
8 |
|
if ( !$event->validateSubscriber($this->getTestCase()) ) { |
|
50
|
|
|
return; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
8 |
|
parent::onTestSetup($event); |
|
54
|
|
|
|
|
55
|
8 |
|
$desired_capabilities = $this->getDesiredCapabilities(); |
|
56
|
|
|
|
|
57
|
8 |
|
if ( getenv('PHPUNIT_MINK_TUNNEL_ID') ) { |
|
58
|
1 |
|
$desired_capabilities['tunnel-identifier'] = getenv('PHPUNIT_MINK_TUNNEL_ID'); |
|
59
|
1 |
|
} |
|
60
|
|
|
|
|
61
|
8 |
|
$this->setDesiredCapabilities($desired_capabilities); |
|
62
|
8 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Returns hostname from browser configuration. |
|
66
|
|
|
* |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
7 |
|
public function getHost() |
|
70
|
|
|
{ |
|
71
|
7 |
|
return $this->getApiUsername() . ':' . $this->getApiKey() . '@ondemand.saucelabs.com'; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Returns desired capabilities from browser configuration. |
|
76
|
|
|
* |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
11 |
|
public function getDesiredCapabilities() |
|
80
|
|
|
{ |
|
81
|
11 |
|
$capabilities = parent::getDesiredCapabilities(); |
|
82
|
|
|
|
|
83
|
11 |
|
if ( !isset($capabilities['platform']) ) { |
|
84
|
9 |
|
$capabilities['platform'] = 'Windows 7'; |
|
85
|
9 |
|
} |
|
86
|
|
|
|
|
87
|
11 |
|
if ( !isset($capabilities['version']) ) { |
|
88
|
9 |
|
$capabilities['version'] = ''; |
|
89
|
9 |
|
} |
|
90
|
|
|
|
|
91
|
11 |
|
return $capabilities; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|