/
SeleniumRCTestCase.php
123 lines (103 loc) · 3.38 KB
/
SeleniumRCTestCase.php
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace Sauce\Sausage;
abstract class SeleniumRCTestCase extends \PHPUnit_Extensions_SeleniumTestCase
{
protected $job_id;
protected $is_local_test = false;
public function setupSpecificBrowser($browser)
{
$this->getDriver($browser);
self::ShareSession(false);
}
protected function getDriver(array $browser)
{
$local = isset($browser['local']) && $browser['local'];
$this->is_local_test = $local;
if (!$local)
SauceTestCommon::RequireSauceConfig();
else
unset($browser['local']);
$defaults = array(
'browser' => 'firefox',
'browserVersion' => '11',
'os' => 'Windows 2008',
'timeout' => 30,
'httpTimeout' => 45,
'host' => 'ondemand.saucelabs.com',
'port' => 80,
'name' => get_called_class().'::'.$this->getName()
);
$local_defaults = array(
'browser' => 'firefox',
'timeout' => 30,
'httpTimeout' => 45,
'host' => 'localhost',
'port' => 4444,
'name' => get_called_class().'::'.$this->getName(),
);
if ($local)
$browser = array_merge($local_defaults, $browser);
else
$browser = array_merge($defaults, $browser);
$checks = array(
'name' => 'string',
'browser' => 'string',
'browserVersion' => 'string',
'timeout' => 'int',
'httpTimeout' => 'int',
'os' => 'string'
);
if ($local) {
unset($checks['browserVersion']);
unset($checks['os']);
}
foreach ($checks as $key => $type) {
$func = 'is_'.$type;
if (!$func($browser[$key])) {
throw new InvalidArgumentException(
'Array element "'.$key.'" is no '.$type.'.'
);
}
}
if ($local)
$driver = new \PHPUnit_Extensions_SeleniumTestCase_Driver();
else
$driver = new SeleniumRCDriver();
if (!$local) {
$driver->setUsername(SAUCE_USERNAME);
$driver->setAccessKey(SAUCE_ACCESS_KEY);
$driver->setOs($browser['os']);
$driver->setBrowserVersion($browser['browserVersion']);
}
$driver->setHost($browser['host']);
$driver->setPort($browser['port']);
$driver->setName($browser['name']);
$driver->setBrowser($browser['browser']);
$driver->setTimeout($browser['timeout']);
$driver->setHttpTimeout($browser['httpTimeout']);
$driver->setTestCase($this);
$driver->setTestId($this->testId);
$this->drivers[0] = $driver;
return $driver;
}
protected function prepareTestSession()
{
$this->job_id = parent::prepareTestSession();
$this->postSessionSetUp();
return $this->job_id;
}
protected function postSessionSetUp()
{
}
public function tearDown()
{
if (!$this->is_local_test) {
SauceTestCommon::ReportStatus($this->job_id, !$this->hasFailed());
}
}
public function spinAssert($msg, $test, $args=array(), $timeout=10)
{
list($result, $msg) = SauceTestCommon::SpinAssert($msg, $test, $args, $timeout);
$this->assertTrue($result, $msg);
}
}