1313use Facebook \WebDriver \WebDriverSelect ;
1414use Facebook \WebDriver \WebDriverBy ;
1515use Facebook \WebDriver \Exception \NoSuchElementException ;
16- use Facebook \WebDriver \WebDriverExpectedCondition ;
1716use Codeception \Exception \ElementNotFound ;
1817use Codeception \Exception \ModuleConfigException ;
1918use Codeception \Exception \ModuleException ;
2019use Codeception \Util \Uri ;
2120use Codeception \Util \ActionSequence ;
22- use Codeception \Util \Locator ;
2321use Magento \FunctionalTestingFramework \Util \Protocol \CurlTransport ;
2422use Magento \FunctionalTestingFramework \Util \Protocol \CurlInterface ;
2523use Magento \Setup \Exception ;
@@ -57,8 +55,6 @@ class MagentoWebDriver extends WebDriver
5755 '//div[@data-role="spinner"] '
5856 ];
5957
60- const DEFAULT_WAIT_TIMEOUT = 10 ;
61-
6258 /**
6359 * The module required fields, to be set in the suite .yml configuration file.
6460 *
@@ -119,16 +115,6 @@ public function _resetConfig()
119115 $ this ->config = ConfigSanitizerUtil::sanitizeWebDriverConfig ($ this ->config );
120116 }
121117
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-
132118 /**
133119 * Returns URL of a host.
134120 *
@@ -315,148 +301,14 @@ public function selectMultipleOptions($selectSearchTextField, $selectSearchResul
315301 }
316302 }
317303
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-
452304 /**
453305 * Wait for all Ajax calls to finish.
454306 *
455307 * @param int $timeout
456308 */
457309 public function waitForAjaxLoad ($ timeout = null )
458310 {
459- $ timeout = $ timeout ?? self :: getDefaultWaitTimeout () ;
311+ $ timeout = $ timeout ?? $ this -> _getConfig ()[ ' pageload_timeout ' ] ;
460312
461313 try {
462314 $ this ->waitForJS ('return !!window.jQuery && window.jQuery.active == 0; ' , $ timeout );
@@ -475,7 +327,7 @@ public function waitForAjaxLoad($timeout = null)
475327 */
476328 public function waitForPageLoad ($ timeout = null )
477329 {
478- $ timeout = $ timeout ?? self :: getDefaultWaitTimeout () ;
330+ $ timeout = $ timeout ?? $ this -> _getConfig ()[ ' pageload_timeout ' ] ;
479331
480332 $ this ->waitForJS ('return document.readyState == "complete" ' , $ timeout );
481333 $ this ->waitForAjaxLoad ($ timeout );
0 commit comments