13
13
use Facebook \WebDriver \WebDriverSelect ;
14
14
use Facebook \WebDriver \WebDriverBy ;
15
15
use Facebook \WebDriver \Exception \NoSuchElementException ;
16
- use Facebook \WebDriver \WebDriverExpectedCondition ;
17
16
use Codeception \Exception \ElementNotFound ;
18
17
use Codeception \Exception \ModuleConfigException ;
19
18
use Codeception \Exception \ModuleException ;
20
19
use Codeception \Util \Uri ;
21
20
use Codeception \Util \ActionSequence ;
22
- use Codeception \Util \Locator ;
23
21
use Magento \FunctionalTestingFramework \Util \Protocol \CurlTransport ;
24
22
use Magento \FunctionalTestingFramework \Util \Protocol \CurlInterface ;
25
23
use Magento \Setup \Exception ;
@@ -57,8 +55,6 @@ class MagentoWebDriver extends WebDriver
57
55
'//div[@data-role="spinner"] '
58
56
];
59
57
60
- const DEFAULT_WAIT_TIMEOUT = 10 ;
61
-
62
58
/**
63
59
* The module required fields, to be set in the suite .yml configuration file.
64
60
*
@@ -119,16 +115,6 @@ public function _resetConfig()
119
115
$ this ->config = ConfigSanitizerUtil::sanitizeWebDriverConfig ($ this ->config );
120
116
}
121
117
122
- /**
123
- * Retrieve default timeout in seconds for 'wait*' actions
124
- *
125
- * @return int
126
- */
127
- public static function getDefaultWaitTimeout ()
128
- {
129
- return getenv ('WAIT_TIMEOUT ' ) ?: self ::DEFAULT_WAIT_TIMEOUT ;
130
- }
131
-
132
118
/**
133
119
* Returns URL of a host.
134
120
*
@@ -315,148 +301,14 @@ public function selectMultipleOptions($selectSearchTextField, $selectSearchResul
315
301
}
316
302
}
317
303
318
- /**
319
- * Wait for $timeout seconds.
320
- *
321
- * @param int|float $timeout secs
322
- * @throws \Codeception\Exception\TestRuntimeException
323
- */
324
- public function wait ($ timeout = null )
325
- {
326
- $ timeout = $ timeout ?? self ::getDefaultWaitTimeout ();
327
-
328
- if ($ timeout >= 1000 ) {
329
- throw new TestRuntimeException (
330
- "
331
- Waiting for more then 1000 seconds: 16.6667 mins \n
332
- Please note that wait method accepts number of seconds as parameter. "
333
- );
334
- }
335
- usleep ($ timeout * 1000000 );
336
- }
337
-
338
- /**
339
- * Waits up to $timeout seconds for the given element to change.
340
- *
341
- * @param $element
342
- * @param \Closure $callback
343
- * @param int $timeout seconds
344
- * @throws \Codeception\Exception\ElementNotFound
345
- * @throws \Exception
346
- */
347
- public function waitForElementChange ($ element , \Closure $ callback , $ timeout = null )
348
- {
349
- $ timeout = $ timeout ?? self ::getDefaultWaitTimeout ();
350
-
351
- $ el = $ this ->matchFirstOrFail ($ this ->baseElement , $ element );
352
- $ checker = function () use ($ el , $ callback ) {
353
- return $ callback ($ el );
354
- };
355
- $ this ->webDriver ->wait ($ timeout )->until ($ checker );
356
- }
357
-
358
- /**
359
- * Waits up to $timeout seconds for an element to appear on the page.
360
- *
361
- * @param $element
362
- * @param int $timeout seconds
363
- * @throws \Exception
364
- */
365
- public function waitForElement ($ element , $ timeout = null )
366
- {
367
- $ timeout = $ timeout ?? self ::getDefaultWaitTimeout ();
368
-
369
- $ condition = WebDriverExpectedCondition::presenceOfElementLocated ($ this ->getLocator ($ element ));
370
- $ this ->webDriver ->wait ($ timeout )->until ($ condition );
371
- }
372
-
373
- /**
374
- * Waits up to $timeout seconds for the given element to be visible on the page.
375
- *
376
- * @param $element
377
- * @param int $timeout seconds
378
- * @throws \Exception
379
- */
380
- public function waitForElementVisible ($ element , $ timeout = null )
381
- {
382
- $ timeout = $ timeout ?? self ::getDefaultWaitTimeout ();
383
-
384
- $ condition = WebDriverExpectedCondition::visibilityOfElementLocated ($ this ->getLocator ($ element ));
385
- $ this ->webDriver ->wait ($ timeout )->until ($ condition );
386
- }
387
-
388
- /**
389
- * Waits up to $timeout seconds for the given element to become invisible.
390
- *
391
- * @param $element
392
- * @param int $timeout seconds
393
- * @throws \Exception
394
- */
395
- public function waitForElementNotVisible ($ element , $ timeout = null )
396
- {
397
- $ timeout = $ timeout ?? self ::getDefaultWaitTimeout ();
398
-
399
- $ condition = WebDriverExpectedCondition::invisibilityOfElementLocated ($ this ->getLocator ($ element ));
400
- $ this ->webDriver ->wait ($ timeout )->until ($ condition );
401
- }
402
-
403
- /**
404
- * Waits up to $timeout seconds for the given string to appear on the page.
405
- *
406
- * @param string $text
407
- * @param int $timeout seconds
408
- * @param string $selector optional
409
- * @throws \Exception
410
- */
411
- public function waitForText ($ text , $ timeout = null , $ selector = null )
412
- {
413
- $ timeout = $ timeout ?? self ::getDefaultWaitTimeout ();
414
-
415
- $ message = sprintf (
416
- 'Waited for %d secs but text %s still not found ' ,
417
- $ timeout ,
418
- Locator::humanReadableString ($ text )
419
- );
420
- if (!$ selector ) {
421
- $ condition = WebDriverExpectedCondition::elementTextContains (WebDriverBy::xpath ('//body ' ), $ text );
422
- $ this ->webDriver ->wait ($ timeout )->until ($ condition , $ message );
423
- return ;
424
- }
425
-
426
- $ condition = WebDriverExpectedCondition::elementTextContains ($ this ->getLocator ($ selector ), $ text );
427
- $ this ->webDriver ->wait ($ timeout )->until ($ condition , $ message );
428
- }
429
-
430
- /**
431
- * Executes JavaScript and waits up to $timeout seconds for it to return true.
432
- *
433
- * @param string $script
434
- * @param int $timeout seconds
435
- * @throws \Exception
436
- */
437
- public function waitForJS ($ script , $ timeout = null )
438
- {
439
- $ timeout = $ timeout ?? self ::getDefaultWaitTimeout ();
440
-
441
- $ condition = function ($ wd ) use ($ script ) {
442
- return $ wd ->executeScript ($ script );
443
- };
444
- $ message = sprintf (
445
- 'Waited for %d secs but script %s still not executed ' ,
446
- $ timeout ,
447
- Locator::humanReadableString ($ script )
448
- );
449
- $ this ->webDriver ->wait ($ timeout )->until ($ condition , $ message );
450
- }
451
-
452
304
/**
453
305
* Wait for all Ajax calls to finish.
454
306
*
455
307
* @param int $timeout
456
308
*/
457
309
public function waitForAjaxLoad ($ timeout = null )
458
310
{
459
- $ timeout = $ timeout ?? self :: getDefaultWaitTimeout () ;
311
+ $ timeout = $ timeout ?? $ this -> _getConfig ()[ ' pageload_timeout ' ] ;
460
312
461
313
try {
462
314
$ this ->waitForJS ('return !!window.jQuery && window.jQuery.active == 0; ' , $ timeout );
@@ -475,7 +327,7 @@ public function waitForAjaxLoad($timeout = null)
475
327
*/
476
328
public function waitForPageLoad ($ timeout = null )
477
329
{
478
- $ timeout = $ timeout ?? self :: getDefaultWaitTimeout () ;
330
+ $ timeout = $ timeout ?? $ this -> _getConfig ()[ ' pageload_timeout ' ] ;
479
331
480
332
$ this ->waitForJS ('return document.readyState == "complete" ' , $ timeout );
481
333
$ this ->waitForAjaxLoad ($ timeout );
0 commit comments