예제 #1
0
파일: WaitUntil.php 프로젝트: pdkhuong/BBG
 /**
  * @param $callback Callback to run until it returns not null or timeout occurs
  * @param null $timeout
  * @return mixed
  * @throws PHPUnit_Extensions_Selenium2TestCase_Exception
  * @throws PHPUnit_Extensions_Selenium2TestCase_WebDriverException
  */
 public function run($callback, $timeout = null)
 {
     if (!is_callable($callback)) {
         throw new PHPUnit_Extensions_Selenium2TestCase_Exception('The valid callback is expected');
     }
     // if there was an implicit timeout specified - remember it and temporarily turn it off
     $implicitWait = $this->_testCase->timeouts()->getLastImplicitWaitValue();
     if ($implicitWait) {
         $this->_testCase->timeouts()->implicitWait(0);
     }
     if (is_null($timeout)) {
         $timeout = $this->_defaultTimeout;
     }
     $timeout /= 1000;
     $endTime = microtime(true) + $timeout;
     $lastException = null;
     while (true) {
         try {
             $result = $callback($this->_testCase);
             if (!is_null($result)) {
                 return $result;
             }
         } catch (Exception $e) {
             $lastException = $e;
         }
         if (microtime(true) > $endTime) {
             if ($implicitWait) {
                 $this->_testCase->timeouts()->implicitWait($implicitWait);
             }
             $message = "Timed out after {$timeout} second" . ($timeout != 1 ? 's' : '');
             throw new PHPUnit_Extensions_Selenium2TestCase_WebDriverException($message, PHPUnit_Extensions_Selenium2TestCase_WebDriverException::Timeout, $lastException);
         }
         usleep($this->_defaultSleepInterval * 1000);
     }
 }
예제 #2
0
 /**
  * Wait for an element to be present on the page
  *
  * @param string $func Locate using - byCss, byXPath, etc
  * @param string $arg  Selector
  *
  * @return PHPUnit_Extensions_Selenium2TestCase_Element  Element waited for
  */
 public function waitForElement($func, $arg)
 {
     $this->_selenium->timeouts()->implicitWait(10000);
     $element = call_user_func_array(
         array($this->_selenium, $func), array($arg)
     );
     $this->_selenium->timeouts()->implicitWait(0);
     return $element;
 }
예제 #3
0
 /**
  * Wait AJAX request
  */
 public function waitForAjax()
 {
     $this->test->waitUntil(function (\PHPUnit_Extensions_Selenium2TestCase $testCase) {
         $status = $testCase->execute(array('script' => "return typeof(jQuery.isActive) == 'undefined' || !jQuery.isActive()", 'args' => array()));
         if ($status) {
             return true;
         } else {
             return null;
         }
     }, intval(MAX_EXECUTION_TIME));
     $this->test->timeouts()->implicitWait(intval(TIME_OUT));
 }
예제 #4
0
    /**
     * Wait AJAX request
     */
    public function waitForAjax()
    {
        $this->test->waitUntil(function (\PHPUnit_Extensions_Selenium2TestCase $testCase) {
            $jsAppActiveCheck = <<<JS
                    var isAppActive = false;
                    try {
                        if (!window.mediatorCachedForSelenium) {
                            window.mediatorCachedForSelenium = require('oroui/js/mediator');
                        }
                        isAppActive = window.mediatorCachedForSelenium.execute('isInAction');
                    } catch(e) {};
                    return !(jQuery && (jQuery.active || jQuery(document.body).hasClass('loading'))) && !isAppActive;
JS;
            $status = $testCase->execute(array('script' => $jsAppActiveCheck, 'args' => array()));
            if ($status) {
                return true;
            } else {
                return null;
            }
        }, intval(MAX_EXECUTION_TIME));
        $this->test->timeouts()->implicitWait(intval(TIME_OUT));
    }