Skip to content

Commit f818e2e

Browse files
committed
Issue #2937073 by tim.plunkett, Saviktor, tedbow: Improve robustness of FieldBlockTest
(cherry picked from commit 06dbc81)
1 parent 54970b9 commit f818e2e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

modules/layout_builder/tests/src/FunctionalJavascript/FieldBlockTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function testFieldBlock() {
9191
$assert_session->fieldNotExists('settings[formatter][settings][format_type]');
9292
$assert_session->fieldExists('settings[formatter][settings][granularity]');
9393
$page->pressButton('Save block');
94-
$assert_session->pageTextContains('The block configuration has been saved.');
94+
$this->assertTrue($assert_session->waitForText('The block configuration has been saved.'));
9595

9696
// Configure the block and change the formatter again.
9797
$this->clickLink('Configure');
@@ -101,7 +101,7 @@ public function testFieldBlock() {
101101
$page->selectFieldOption('settings[formatter][settings][format_type]', 'long');
102102

103103
$page->pressButton('Save block');
104-
$assert_session->pageTextContains('The block configuration has been saved.');
104+
$this->assertTrue($assert_session->waitForText('The block configuration has been saved.'));
105105

106106
// Assert that the field value is updated.
107107
$this->clickLink('Configure');

tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,26 @@ public function waitForElementVisible($selector, $locator, $timeout = 10000) {
101101
return $result;
102102
}
103103

104+
/**
105+
* Waits for the specified text and returns its element when available.
106+
*
107+
* @param string $text
108+
* The text to wait for.
109+
* @param int $timeout
110+
* (Optional) Timeout in milliseconds, defaults to 10000.
111+
*
112+
* @return \Behat\Mink\Element\NodeElement|null
113+
* The page element node if found and visible, NULL if not.
114+
*/
115+
public function waitForText($text, $timeout = 10000) {
116+
$page = $this->session->getPage();
117+
return $page->waitFor($timeout / 1000, function () use ($page, $text) {
118+
$actual = preg_replace('/\s+/u', ' ', $page->getText());
119+
$regex = '/' . preg_quote($text, '/') . '/ui';
120+
return (bool) preg_match($regex, $actual);
121+
});
122+
}
123+
104124
/**
105125
* Waits for a button (input[type=submit|image|button|reset], button) with
106126
* specified locator and returns it.

0 commit comments

Comments
 (0)