You are here

public function JSWebAssert::waitForText in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php \Drupal\FunctionalJavascriptTests\JSWebAssert::waitForText()

Waits for the specified text and returns its element when available.

Parameters

string $text: The text to wait for.

int $timeout: (Optional) Timeout in milliseconds, defaults to 10000.

Return value

\Behat\Mink\Element\NodeElement|null The page element node if found and visible, NULL if not.

File

core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php, line 141

Class

JSWebAssert
Defines a class with methods for asserting presence of elements during tests.

Namespace

Drupal\FunctionalJavascriptTests

Code

public function waitForText($text, $timeout = 10000) {
  $page = $this->session
    ->getPage();
  return $page
    ->waitFor($timeout / 1000, function () use ($page, $text) {
    $actual = preg_replace('/\\s+/u', ' ', $page
      ->getText());
    $regex = '/' . preg_quote($text, '/') . '/ui';
    return (bool) preg_match($regex, $actual);
  });
}