diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderDisableInteractionsTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderDisableInteractionsTest.php
index d7a05a7c7015..a32ff7d232da 100644
--- a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderDisableInteractionsTest.php
+++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderDisableInteractionsTest.php
@@ -3,12 +3,12 @@
namespace Drupal\Tests\layout_builder\FunctionalJavascript;
use Behat\Mink\Element\NodeElement;
+use Behat\Mink\Exception\ElementHtmlException;
use Drupal\block_content\Entity\BlockContent;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait;
-use WebDriver\Exception\UnknownError;
/**
* Tests the Layout Builder disables interactions of rendered blocks.
@@ -73,7 +73,7 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase {
'info' => 'Block with iframe',
'body' => [
// Add iframe that should be non-interactive in Layout Builder preview.
- 'value' => '',
+ 'value' => '',
'format' => 'full_html',
],
])->save();
@@ -83,6 +83,10 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase {
* Tests that forms and links are disabled in the Layout Builder preview.
*/
public function testFormsLinksDisabled() {
+ // Resize window due to bug in Chromedriver when clicking on overlays over
+ // iFrames.
+ // @see https://bugs.chromium.org/p/chromedriver/issues/detail?id=2758
+ $this->getSession()->resizeWindow(1200, 1200);
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
@@ -170,7 +174,7 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase {
$tag_name = $element->getTagName();
$this->fail(new FormattableMarkup("@tag_name was clickable when it shouldn't have been", ['@tag_name' => $tag_name]));
}
- catch (UnknownError $e) {
+ catch (\Exception $e) {
$this->assertContains('is not clickable at point', $e->getMessage());
}
}
@@ -202,7 +206,7 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase {
$this->clickContextualLink('.block-field-blocknodebundle-with-section-fieldbody [data-contextual-id^="layout_builder_block"]', 'Configure');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '.ui-dialog-titlebar [title="Close"]'));
$page->pressButton('Close');
- $this->assertNoElementAfterWait('#drupal-off-canvas');
+ $this->assertNoElementAfterWait('css', '#drupal-off-canvas');
// Run the steps a second time after closing dialog, which reverses the
// order that behaviors.layoutBuilderDisableInteractiveElements and
@@ -210,7 +214,7 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase {
$this->clickContextualLink('.block-field-blocknodebundle-with-section-fieldbody [data-contextual-id^="layout_builder_block"]', 'Configure');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas'));
$page->pressButton('Close');
- $this->assertNoElementAfterWait('#drupal-off-canvas');
+ $this->assertNoElementAfterWait('css', '#drupal-off-canvas');
$this->assertContextualLinkRetainsMouseup();
}
@@ -300,20 +304,33 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase {
}
/**
- * Waits for an element to be removed from the page.
+ * Asserts that no matching element exists on the page after a wait.
*
- * @param string $selector
- * CSS selector.
+ * @param string $selector_type
+ * The element selector type (CSS, XPath).
+ * @param string|array $selector
+ * The element selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
* @param string $message
- * (optional) Custom message to display with the assertion.
+ * (optional) The exception message.
*
- * @todo: Remove after https://www.drupal.org/project/drupal/issues/2892440
+ * @throws \Behat\Mink\Exception\ElementHtmlException
+ * When an element still exists on the page.
*/
- public function assertNoElementAfterWait($selector, $timeout = 10000, $message = '') {
- $condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
- $this->assertJsCondition($condition, $timeout, $message);
+ public function assertNoElementAfterWait($selector_type, $selector, $timeout = 10000, $message = 'Element exists on the page.') {
+ $start = microtime(TRUE);
+ $end = $start + ($timeout / 1000);
+ $page = $this->getSession()->getPage();
+ do {
+ $node = $page->find($selector_type, $selector);
+ if (empty($node)) {
+ return;
+ }
+ usleep(100000);
+ } while (microtime(TRUE) < $end);
+
+ throw new ElementHtmlException($message, $this->session->getDriver(), $node);
}
}