You are here

public function JSWebAssert::waitForText in Drupal 9

Same name and namespace in other branches
  1. 8 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

bool TRUE if not found, FALSE if found.

File

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

Class

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

Namespace

Drupal\FunctionalJavascriptTests

Code

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