Commit 6c78d267 authored by xjm's avatar xjm

Issue #2937073 by tim.plunkett, Saviktor, tedbow: Improve robustness of FieldBlockTest

(cherry picked from commit 06dbc81f)
parent 9efe560f
......@@ -91,7 +91,7 @@ public function testFieldBlock() {
$assert_session->fieldNotExists('settings[formatter][settings][format_type]');
$assert_session->fieldExists('settings[formatter][settings][granularity]');
$page->pressButton('Save block');
$assert_session->pageTextContains('The block configuration has been saved.');
$this->assertTrue($assert_session->waitForText('The block configuration has been saved.'));
// Configure the block and change the formatter again.
$this->clickLink('Configure');
......@@ -101,7 +101,7 @@ public function testFieldBlock() {
$page->selectFieldOption('settings[formatter][settings][format_type]', 'long');
$page->pressButton('Save block');
$assert_session->pageTextContains('The block configuration has been saved.');
$this->assertTrue($assert_session->waitForText('The block configuration has been saved.'));
// Assert that the field value is updated.
$this->clickLink('Configure');
......
......@@ -101,6 +101,26 @@ public function waitForElementVisible($selector, $locator, $timeout = 10000) {
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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment