function DrupalSelenium2Driver::waitFor

Same name in other branches
  1. 10 core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php \Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver::waitFor()
  2. 11.x core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php \Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver::waitFor()

Waits for a callback to return a truthy result and returns it.

Parameters

int|float $timeout: Maximal allowed waiting time in seconds.

callable $callback: Callback, which result is both used as waiting condition and returned. Will receive reference to `this driver` as first argument.

Return value

mixed The result of the callback.

2 calls to DrupalSelenium2Driver::waitFor()
DrupalSelenium2Driver::click in core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php
DrupalSelenium2Driver::setValue in core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php

File

core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php, line 195

Class

DrupalSelenium2Driver
Provides a driver for Selenium testing.

Namespace

Drupal\FunctionalJavascriptTests

Code

private function waitFor($timeout, callable $callback) {
    $start = microtime(TRUE);
    $end = $start + $timeout;
    do {
        $result = call_user_func($callback, $this);
        if ($result) {
            break;
        }
        usleep(10000);
    } while (microtime(TRUE) < $end);
    return $result;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.