diff core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
line wrap: on
line diff
--- a/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php	Tue Jul 10 15:07:59 2018 +0100
+++ b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php	Thu Feb 28 13:21:36 2019 +0000
@@ -100,6 +100,27 @@
 
     return $result;
   }
+
+  /**
+   * Waits for the specified text and returns its element when available.
+   *
+   * @param string $text
+   *   The text to wait for.
+   * @param int $timeout
+   *   (Optional) Timeout in milliseconds, defaults to 10000.
+   *
+   * @return \Behat\Mink\Element\NodeElement|null
+   *   The page element node if found and visible, NULL if not.
+   */
+  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);
+    });
+  }
+
   /**
    * Waits for a button (input[type=submit|image|button|reset], button) with
    * specified locator and returns it.