diff --git a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php index 9d806453d1..ff5ba1f29b 100644 --- a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php +++ b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php @@ -83,7 +83,7 @@ public function testBlocks($block_plugin, $new_page_text, $element_selector, $la $this->waitForNoElement("#toolbar-administration a.is-active"); } $page->find('css', $toolbar_item)->click(); - $web_assert->waitForElementVisible('css', "{$toolbar_item}.is-active"); + $this->assertElementVisibleAfterWait('css', "{$toolbar_item}.is-active"); } $this->enableEditMode(); if (isset($toolbar_item)) { @@ -107,7 +107,10 @@ public function testBlocks($block_plugin, $new_page_text, $element_selector, $la $page->pressButton($button_text); // Make sure the changes are present. $new_page_text_locator = "$block_selector $label_selector:contains($new_page_text)"; - $web_assert->waitForElement('css', $new_page_text_locator); + $this->assertElementVisibleAfterWait('css', $new_page_text_locator); + // After the new page text is on the page wait to make sure all Ajax + // request are completed on the new page. + $web_assert->assertWaitOnAjaxRequest(); } $this->openBlockForm($block_selector); @@ -255,7 +258,7 @@ public function testQuickEditLinks() { $this->drupalGet('node/' . $node->id()); // Waiting for Toolbar module. // @todo Remove the hack after https://www.drupal.org/node/2542050. - $web_assert->waitForElementVisible('css', '.toolbar-fixed'); + $this->assertElementVisibleAfterWait('css', '.toolbar-fixed'); // Waiting for Toolbar animation. $web_assert->assertWaitOnAjaxRequest(); // The 2nd page load we should already be in edit mode. @@ -264,7 +267,7 @@ public function testQuickEditLinks() { } // In Edit mode clicking field should open QuickEdit toolbar. $page->find('css', $body_selector)->click(); - $web_assert->waitForElementVisible('css', $quick_edit_selector); + $this->assertElementVisibleAfterWait('css', $quick_edit_selector); $this->disableEditMode(); // Exiting Edit mode should close QuickEdit toolbar. @@ -275,7 +278,7 @@ public function testQuickEditLinks() { $this->enableEditMode(); $this->openBlockForm($block_selector); $page->find('css', $body_selector)->click(); - $web_assert->waitForElementVisible('css', $quick_edit_selector); + $this->assertElementVisibleAfterWait('css', $quick_edit_selector); // Off-canvas dialog should be closed when opening QuickEdit toolbar. $this->waitForOffCanvasToClose(); @@ -289,7 +292,7 @@ public function testQuickEditLinks() { $this->disableEditMode(); // Open QuickEdit toolbar before going into Edit mode. $this->clickContextualLink($node_selector, "Quick edit"); - $web_assert->waitForElementVisible('css', $quick_edit_selector); + $this->assertElementVisibleAfterWait('css', $quick_edit_selector); // Open off-canvas and enter Edit mode via contextual link. $this->clickContextualLink($block_selector, "Quick edit"); $this->waitForOffCanvasToOpen(); @@ -298,7 +301,7 @@ public function testQuickEditLinks() { // Open QuickEdit toolbar via contextual link while in Edit mode. $this->clickContextualLink($node_selector, "Quick edit", FALSE); $this->waitForOffCanvasToClose(); - $web_assert->waitForElementVisible('css', $quick_edit_selector); + $this->assertElementVisibleAfterWait('css', $quick_edit_selector); $this->disableEditMode(); } } diff --git a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInJavascriptTestBase.php b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInJavascriptTestBase.php index 2dcc40fb44..ea2fe948fb 100644 --- a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInJavascriptTestBase.php +++ b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInJavascriptTestBase.php @@ -42,7 +42,7 @@ public function enableTheme($theme) { protected function waitForOffCanvasToOpen() { $web_assert = $this->assertSession(); $web_assert->assertWaitOnAjaxRequest(); - $web_assert->waitForElementVisible('css', '#drupal-off-canvas'); + $this->assertElementVisibleAfterWait('css', '#drupal-off-canvas'); } /** @@ -125,7 +125,7 @@ protected function waitForToolbarToLoad() { $web_assert = $this->assertSession(); // Waiting for Toolbar module. // @todo Remove the hack after https://www.drupal.org/node/2542050. - $web_assert->waitForElementVisible('css', '.toolbar-fixed'); + $this->assertElementVisibleAfterWait('css', '.toolbar-fixed'); // Waiting for Toolbar animation. $web_assert->assertWaitOnAjaxRequest(); } @@ -140,4 +140,19 @@ protected function getTestThemes() { return ['bartik', 'stark', 'classy', 'stable']; } + /** + * Assert the specified selector is visible after a wait. + * + * @param string $selector + * The selector engine name. See ElementInterface::findAll() for the + * supported selectors. + * @param string|array $locator + * The selector locator. + * @param int $timeout + * (Optional) Timeout in milliseconds, defaults to 10000. + */ + protected function assertElementVisibleAfterWait($selector, $locator, $timeout = 10000) { + $this->assertNotEmpty($this->assertSession()->waitForElementVisible($selector, $locator, $timeout)); + } + }