You are here

public function VarbaseContext::iWaitMaxOfSecondsForThePageToBeReadyAndLoaded in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.5

Same name and namespace in other branches
  1. 8.8 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iWaitMaxOfSecondsForThePageToBeReadyAndLoaded()
  2. 8.4 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iWaitMaxOfSecondsForThePageToBeReadyAndLoaded()
  3. 8.6 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iWaitMaxOfSecondsForThePageToBeReadyAndLoaded()
  4. 8.7 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iWaitMaxOfSecondsForThePageToBeReadyAndLoaded()
  5. 9.0.x tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iWaitMaxOfSecondsForThePageToBeReadyAndLoaded()

#varbase : I wait max of seconds for the page to be ready and loaded.

Exmaple 1: And wait Exmaple 2: And I wait Example 3: And wait for the page Example 4: And I wait for the page Example 5: And wait max of 5 seconds Example 6: And wait max of 5s Example 7: And I wait max of 5s Example 8: And I wait max of "5" seconds Example 9: And I wait max of "5" seconds for the page to be ready and loaded

@Given /^(?:|I )wait max of "(?P<time>\d+)" second(?:|s)(?:| for the page to be ready and loaded)$/ @Given /^(?:|I )wait max of (?P<time>\d+) second(?:|s)(?:| for the page to be ready and loaded)$/ @Given /^(?:|I )wait max of (?P<time>\d+)s(?:| for the page to be ready and loaded)$/ @Given /^(?:|I )wait(?:| for the page)$/

Throws

BehaviorException If timeout is reached

File

tests/features/bootstrap/VarbaseContext.php, line 183

Class

VarbaseContext
Defines application features from the specific context.

Code

public function iWaitMaxOfSecondsForThePageToBeReadyAndLoaded($time = 10000) {
  if (!$this
    ->getSession()
    ->getDriver() instanceof Selenium2Driver) {
    return;
  }
  $start = microtime(true);
  $end = $start + $time / 1000.0;
  $defaultCondition = true;
  $conditions = [
    "document.readyState == 'complete'",
    // Page is ready
    "typeof \$ != 'undefined'",
    // jQuery is loaded
    "!\$.active",
    // No ajax request is active
    "\$('#page').css('display') == 'block'",
    // Page is displayed (no progress bar)
    "\$('.loading-mask').css('display') == 'none'",
    // Page is not loading (no black mask loading page)
    "\$('.jstree-loading').length == 0",
  ];
  $condition = implode(' && ', $conditions);

  // Make sure the AJAX calls are fired up before checking the condition
  $this
    ->getSession()
    ->wait(100, false);
  $this
    ->getSession()
    ->wait($time, $condition);

  // Check if we reached the timeout unless the condition is false to explicitly wait the specified time
  if ($condition !== false && microtime(true) > $end) {
    throw new BehaviorException(sprintf('Timeout of %d reached when checking on %s', $time, $condition));
  }
}