41
41
* @link http://www.phpunit.de/
42
42
* @since File available since Release 1.2.0
43
43
*/
44
+
45
+ namespace PHPUnit \Extensions ;
46
+
47
+ use Exception ;
48
+ use InvalidArgumentException ;
49
+ use PHPUnit \Extensions \Selenium2TestCase \Element ;
50
+ use PHPUnit \Extensions \Selenium2TestCase \Element \Select ;
51
+ use PHPUnit \Extensions \Selenium2TestCase \ElementCriteria ;
52
+ use PHPUnit \Extensions \Selenium2TestCase \KeysHolder ;
53
+ use PHPUnit \Extensions \Selenium2TestCase \NoSeleniumException ;
54
+ use PHPUnit \Extensions \Selenium2TestCase \Session ;
55
+ use PHPUnit \Extensions \Selenium2TestCase \Session \Timeouts ;
56
+ use PHPUnit \Extensions \Selenium2TestCase \SessionStrategy ;
57
+ use PHPUnit \Extensions \Selenium2TestCase \SessionStrategy \Isolated ;
58
+ use PHPUnit \Extensions \Selenium2TestCase \SessionStrategy \Shared ;
59
+ use PHPUnit \Extensions \Selenium2TestCase \URL ;
60
+ use PHPUnit \Extensions \Selenium2TestCase \WaitUntil ;
61
+ use PHPUnit \Extensions \Selenium2TestCase \Window ;
62
+ use PHPUnit \Extensions \SeleniumCommon \RemoteCoverage ;
44
63
use PHPUnit \Framework \TestCase ;
45
64
use PHPUnit \Framework \TestResult ;
46
65
use PHPUnit \Util \InvalidArgumentHelper ;
66
+ use RuntimeException ;
67
+ use Throwable ;
47
68
48
69
/**
49
70
* TestCase class that uses Selenium 2
60
81
* @method void acceptAlert() Press OK on an alert, or confirms a dialog
61
82
* @method mixed alertText() alertText($value = NULL) Gets the alert dialog text, or sets the text for a prompt dialog
62
83
* @method void back()
63
- * @method \PHPUnit_Extensions_Selenium2TestCase_Element byClassName() byClassName($value)
64
- * @method \PHPUnit_Extensions_Selenium2TestCase_Element byCssSelector() byCssSelector($value)
65
- * @method \PHPUnit_Extensions_Selenium2TestCase_Element byId() byId($value)
66
- * @method \PHPUnit_Extensions_Selenium2TestCase_Element byLinkText() byLinkText($value)
67
- * @method \PHPUnit_Extensions_Selenium2TestCase_Element byPartialLinkText() byPartialLinkText($value)
68
- * @method \PHPUnit_Extensions_Selenium2TestCase_Element byName() byName($value)
69
- * @method \PHPUnit_Extensions_Selenium2TestCase_Element byTag() byTag($value)
70
- * @method \PHPUnit_Extensions_Selenium2TestCase_Element byXPath() byXPath($value)
84
+ * @method Element byClassName() byClassName($value)
85
+ * @method Element byCssSelector() byCssSelector($value)
86
+ * @method Element byId() byId($value)
87
+ * @method Element byLinkText() byLinkText($value)
88
+ * @method Element byPartialLinkText() byPartialLinkText($value)
89
+ * @method Element byName() byName($value)
90
+ * @method Element byTag() byTag($value)
91
+ * @method Element byXPath() byXPath($value)
71
92
* @method void click() click(int $button = 0) Click any mouse button (at the coordinates set by the last moveto command).
72
93
* @method void clickOnElement() clickOnElement($id)
73
94
* @method string currentScreenshot() BLOB of the image file
74
95
* @method void dismissAlert() Press Cancel on an alert, or does not confirm a dialog
75
96
* @method void doubleclick() Double clicks (at the coordinates set by the last moveto command).
76
- * @method \PHPUnit_Extensions_Selenium2TestCase_Element element() element(\PHPUnit_Extensions_Selenium2TestCase_ElementCriteria $criteria) Retrieves an element
77
- * @method array elements() elements(\PHPUnit_Extensions_Selenium2TestCase_ElementCriteria $criteria) Retrieves an array of Element instances
97
+ * @method Element element() element(ElementCriteria $criteria) Retrieves an element
98
+ * @method array elements() elements(ElementCriteria $criteria) Retrieves an array of Element instances
78
99
* @method string execute() execute($javaScriptCode) Injects arbitrary JavaScript in the page and returns the last
79
100
* @method string executeAsync() executeAsync($javaScriptCode) Injects arbitrary JavaScript and wait for the callback (last element of arguments) to be called
80
101
* @method void forward()
81
- * @method void frame() frame(mixed $element) Changes the focus to a frame in the page (by frameCount of type int, htmlId of type string, htmlName of type string or element of type \PHPUnit_Extensions_Selenium2TestCase_Element )
82
- * @method void moveto() moveto(\PHPUnit_Extensions_Selenium2TestCase_Element $element) Move the mouse by an offset of the specificed element.
102
+ * @method void frame() frame(mixed $element) Changes the focus to a frame in the page (by frameCount of type int, htmlId of type string, htmlName of type string or element of type Element )
103
+ * @method void moveto() moveto(Element $element) Move the mouse by an offset of the specificed element.
83
104
* @method void refresh()
84
- * @method \PHPUnit_Extensions_Selenium2TestCase_Element_Select select() select($element)
105
+ * @method Select select() select($element)
85
106
* @method string source() Returns the HTML source of the page
86
- * @method \PHPUnit_Extensions_Selenium2TestCase_Session_Timeouts timeouts()
107
+ * @method Timeouts timeouts()
87
108
* @method string title()
88
109
* @method void|string url() url($url = NULL)
89
- * @method PHPUnit_Extensions_Selenium2TestCase_ElementCriteria using() using($strategy) Factory Method for Criteria objects
110
+ * @method ElementCriteria using() using($strategy) Factory Method for Criteria objects
90
111
* @method void window() window($name) Changes the focus to another window
91
112
* @method string windowHandle() Retrieves the current window handle
92
113
* @method string windowHandles() Retrieves a list of all available window handles
96
117
* @method array logTypes() Get available log types.
97
118
* @method void closeWindow() Close the current window.
98
119
* @method void stop() Close the current window and clear session data.
99
- * @method \PHPUnit_Extensions_Selenium2TestCase_Element active() Get the element on the page that currently has focus.
100
- * @method \PHPUnit_Extensions_Selenium2TestCase_Window currentWindow() get the current Window Object
120
+ * @method Element active() Get the element on the page that currently has focus.
121
+ * @method Window currentWindow() get the current Window Object
101
122
*/
102
- abstract class PHPUnit_Extensions_Selenium2TestCase extends TestCase
123
+ abstract class Selenium2TestCase extends TestCase
103
124
{
104
125
const VERSION = '7.0.1 ' ;
105
126
@@ -109,7 +130,7 @@ abstract class PHPUnit_Extensions_Selenium2TestCase extends TestCase
109
130
protected $ coverageScriptUrl ;
110
131
111
132
/**
112
- * @var PHPUnit_Extensions_Selenium2TestCase_Session
133
+ * @var Session
113
134
*/
114
135
private $ session ;
115
136
@@ -119,12 +140,12 @@ abstract class PHPUnit_Extensions_Selenium2TestCase extends TestCase
119
140
private $ parameters ;
120
141
121
142
/**
122
- * @var PHPUnit_Extensions_Selenium2TestCase_SessionStrategy
143
+ * @var SessionStrategy
123
144
*/
124
145
protected static $ sessionStrategy ;
125
146
126
147
/**
127
- * @var PHPUnit_Extensions_Selenium2TestCase_SessionStrategy
148
+ * @var SessionStrategy
128
149
*/
129
150
protected static $ browserSessionStrategy ;
130
151
@@ -143,7 +164,7 @@ abstract class PHPUnit_Extensions_Selenium2TestCase extends TestCase
143
164
private static $ defaultWaitUntilSleepInterval = 500 ;
144
165
145
166
/**
146
- * @var PHPUnit_Extensions_Selenium2TestCase_SessionStrategy
167
+ * @var SessionStrategy
147
168
*/
148
169
protected $ localSessionStrategy ;
149
170
@@ -163,7 +184,7 @@ abstract class PHPUnit_Extensions_Selenium2TestCase extends TestCase
163
184
private $ collectCodeCoverageInformation ;
164
185
165
186
/**
166
- * @var PHPUnit_Extensions_Selenium2TestCase_KeysHolder
187
+ * @var KeysHolder
167
188
*/
168
189
private $ keysHolder ;
169
190
@@ -183,7 +204,7 @@ public static function shareSession($shareSession)
183
204
if (!$ shareSession ) {
184
205
self ::$ sessionStrategy = self ::defaultSessionStrategy ();
185
206
} else {
186
- self ::$ sessionStrategy = new PHPUnit_Extensions_Selenium2TestCase_SessionStrategy_Shared (
207
+ self ::$ sessionStrategy = new Shared (
187
208
self ::defaultSessionStrategy (), self ::$ keepSessionOnFailure
188
209
);
189
210
}
@@ -209,7 +230,7 @@ private static function sessionStrategy()
209
230
210
231
private static function defaultSessionStrategy ()
211
232
{
212
- return new PHPUnit_Extensions_Selenium2TestCase_SessionStrategy_Isolated ;
233
+ return new Isolated ;
213
234
}
214
235
215
236
/**
@@ -260,7 +281,7 @@ public function __construct($name = NULL, array $data = array(), $dataName = '')
260
281
'secure ' => FALSE
261
282
);
262
283
263
- $ this ->keysHolder = new PHPUnit_Extensions_Selenium2TestCase_KeysHolder ();
284
+ $ this ->keysHolder = new KeysHolder ();
264
285
}
265
286
266
287
public function setupSpecificBrowser ($ params )
@@ -293,9 +314,9 @@ protected function setUpSessionStrategy($params)
293
314
if ($ strat != "isolated " && $ strat != "shared " ) {
294
315
throw new InvalidArgumentException ("Session strategy must be either 'isolated' or 'shared' " );
295
316
} elseif ($ strat == "isolated " ) {
296
- self ::$ browserSessionStrategy = new PHPUnit_Extensions_Selenium2TestCase_SessionStrategy_Isolated ;
317
+ self ::$ browserSessionStrategy = new Isolated ;
297
318
} else {
298
- self ::$ browserSessionStrategy = new PHPUnit_Extensions_Selenium2TestCase_SessionStrategy_Shared (self ::defaultSessionStrategy (), self ::$ keepSessionOnFailure );
319
+ self ::$ browserSessionStrategy = new Shared (self ::defaultSessionStrategy (), self ::$ keepSessionOnFailure );
299
320
}
300
321
} else {
301
322
self ::$ browserSessionStrategy = self ::defaultSessionStrategy ();
@@ -320,7 +341,7 @@ public function prepareSession()
320
341
if (!$ this ->session ) {
321
342
$ this ->session = $ this ->getStrategy ()->session ($ this ->parameters );
322
343
}
323
- } catch (PHPUnit_Extensions_Selenium2TestCase_NoSeleniumException $ e ) {
344
+ } catch (NoSeleniumException $ e ) {
324
345
$ this ->markTestSkipped ("The Selenium Server is not active on host {$ this ->parameters ['host ' ]} at port {$ this ->parameters ['port ' ]}. " );
325
346
}
326
347
return $ this ->session ;
@@ -339,7 +360,7 @@ public function run(TestResult $result = NULL): TestResult
339
360
parent ::run ($ result );
340
361
341
362
if ($ this ->collectCodeCoverageInformation ) {
342
- $ coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage (
363
+ $ coverage = new RemoteCoverage (
343
364
$ this ->coverageScriptUrl ,
344
365
$ this ->testId
345
366
);
@@ -394,7 +415,7 @@ protected function runTest()
394
415
395
416
public static function suite ($ className )
396
417
{
397
- return PHPUnit_Extensions_SeleniumTestSuite ::fromTestCaseClass ($ className );
418
+ return SeleniumTestSuite ::fromTestCaseClass ($ className );
398
419
}
399
420
400
421
public function onNotSuccessfulTest (Throwable $ e ): void
@@ -413,7 +434,7 @@ public function onNotSuccessfulTest(Throwable $e): void
413
434
public function __call ($ command , $ arguments )
414
435
{
415
436
if ($ this ->session === NULL ) {
416
- throw new PHPUnit_Extensions_Selenium2TestCase_Exception ("There is currently no active session to execute the ' $ command' command. You're probably trying to set some option in setUp() with an incorrect setter name. You may consider using setUpPage() instead. " );
437
+ throw new \ PHPUnit \ Extensions \ Selenium2TestCase \ Exception ("There is currently no active session to execute the ' $ command' command. You're probably trying to set some option in setUp() with an incorrect setter name. You may consider using setUpPage() instead. " );
417
438
}
418
439
$ result = call_user_func_array (
419
440
array ($ this ->session , $ command ), $ arguments
@@ -504,7 +525,7 @@ public function setBrowserUrl($browserUrl)
504
525
throw InvalidArgumentHelper::factory (1 , 'string ' );
505
526
}
506
527
507
- $ this ->parameters ['browserUrl ' ] = new PHPUnit_Extensions_Selenium2TestCase_URL ($ browserUrl );
528
+ $ this ->parameters ['browserUrl ' ] = new URL ($ browserUrl );
508
529
}
509
530
510
531
public function getBrowserUrl ()
@@ -572,7 +593,7 @@ public function getSessionId()
572
593
*/
573
594
public function waitUntil ($ callback , $ timeout = NULL )
574
595
{
575
- $ waitUntil = new PHPUnit_Extensions_Selenium2TestCase_WaitUntil ($ this );
596
+ $ waitUntil = new WaitUntil ($ this );
576
597
return $ waitUntil ->run ($ callback , $ timeout );
577
598
}
578
599
@@ -581,8 +602,8 @@ public function waitUntil($callback, $timeout = NULL)
581
602
* Deprecated due to issues with IE webdriver. Use keys() method instead
582
603
* @deprecated
583
604
* @param string $name
584
- * @throws PHPUnit_Extensions_Selenium2TestCase_Exception
585
- * @see PHPUnit_Extensions_Selenium2TestCase_KeysHolder
605
+ * @throws \PHPUnit\Extensions\Selenium2TestCase\Exception
606
+ * @see KeysHolder
586
607
*/
587
608
public function keysSpecial ($ name )
588
609
{
0 commit comments