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

8.7.x
xjm 2019-01-28 17:54:09 -06:00
parent e1832a2c2b
commit 06dbc81f02
2 changed files with 22 additions and 2 deletions

View File

@ -91,7 +91,7 @@ class FieldBlockTest extends WebDriverTestBase {
$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 @@ class FieldBlockTest extends WebDriverTestBase {
$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');

View File

@ -101,6 +101,26 @@ JS;
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.