Commit 93c269ac authored by catch's avatar catch

Issue #3056536 by alexpott, tedbow: LayoutBuilderDisableInteractionsTest randomly fails

(cherry picked from commit e46168f2)
parent db905bd4
......@@ -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 @@ protected function setUp() {
'info' => 'Block with iframe',
'body' => [
// Add iframe that should be non-interactive in Layout Builder preview.
'value' => '<iframe id="iframe-that-should-be-disabled" width="560" height="315" src="https://www.youtube.com/embed/gODZzSOelss" frameborder="0"></iframe>',
'value' => '<iframe id="iframe-that-should-be-disabled" width="1" height="1" src="https://www.youtube.com/embed/gODZzSOelss" frameborder="0"></iframe>',
'format' => 'full_html',
],
])->save();
......@@ -83,6 +83,10 @@ protected function setUp() {
* 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 @@ protected function assertElementUnclickable(NodeElement $element) {
$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 @@ protected function assertContextualLinksClickable() {
$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 @@ protected function assertContextualLinksClickable() {
$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 @@ protected function movePointerTo($selector) {
}
/**
* 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);
}
}
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