Commit e46168f2 authored by catch's avatar catch

Issue #3056536 by alexpott, tedbow: LayoutBuilderDisableInteractionsTest randomly fails

parent a84d05f2
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
namespace Drupal\Tests\layout_builder\FunctionalJavascript; namespace Drupal\Tests\layout_builder\FunctionalJavascript;
use Behat\Mink\Element\NodeElement; use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ElementHtmlException;
use Drupal\block_content\Entity\BlockContent; use Drupal\block_content\Entity\BlockContent;
use Drupal\block_content\Entity\BlockContentType; use Drupal\block_content\Entity\BlockContentType;
use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Render\FormattableMarkup;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase; use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait; use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait;
use WebDriver\Exception\UnknownError;
/** /**
* Tests the Layout Builder disables interactions of rendered blocks. * Tests the Layout Builder disables interactions of rendered blocks.
...@@ -73,7 +73,7 @@ protected function setUp() { ...@@ -73,7 +73,7 @@ protected function setUp() {
'info' => 'Block with iframe', 'info' => 'Block with iframe',
'body' => [ 'body' => [
// Add iframe that should be non-interactive in Layout Builder preview. // 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', 'format' => 'full_html',
], ],
])->save(); ])->save();
...@@ -83,6 +83,10 @@ protected function setUp() { ...@@ -83,6 +83,10 @@ protected function setUp() {
* Tests that forms and links are disabled in the Layout Builder preview. * Tests that forms and links are disabled in the Layout Builder preview.
*/ */
public function testFormsLinksDisabled() { 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(); $assert_session = $this->assertSession();
$page = $this->getSession()->getPage(); $page = $this->getSession()->getPage();
...@@ -170,7 +174,7 @@ protected function assertElementUnclickable(NodeElement $element) { ...@@ -170,7 +174,7 @@ protected function assertElementUnclickable(NodeElement $element) {
$tag_name = $element->getTagName(); $tag_name = $element->getTagName();
$this->fail(new FormattableMarkup("@tag_name was clickable when it shouldn't have been", ['@tag_name' => $tag_name])); $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()); $this->assertContains('is not clickable at point', $e->getMessage());
} }
} }
...@@ -202,7 +206,7 @@ protected function assertContextualLinksClickable() { ...@@ -202,7 +206,7 @@ protected function assertContextualLinksClickable() {
$this->clickContextualLink('.block-field-blocknodebundle-with-section-fieldbody [data-contextual-id^="layout_builder_block"]', 'Configure'); $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"]')); $this->assertNotEmpty($assert_session->waitForElementVisible('css', '.ui-dialog-titlebar [title="Close"]'));
$page->pressButton('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 // Run the steps a second time after closing dialog, which reverses the
// order that behaviors.layoutBuilderDisableInteractiveElements and // order that behaviors.layoutBuilderDisableInteractiveElements and
...@@ -210,7 +214,7 @@ protected function assertContextualLinksClickable() { ...@@ -210,7 +214,7 @@ protected function assertContextualLinksClickable() {
$this->clickContextualLink('.block-field-blocknodebundle-with-section-fieldbody [data-contextual-id^="layout_builder_block"]', 'Configure'); $this->clickContextualLink('.block-field-blocknodebundle-with-section-fieldbody [data-contextual-id^="layout_builder_block"]', 'Configure');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas')); $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas'));
$page->pressButton('Close'); $page->pressButton('Close');
$this->assertNoElementAfterWait('#drupal-off-canvas'); $this->assertNoElementAfterWait('css', '#drupal-off-canvas');
$this->assertContextualLinkRetainsMouseup(); $this->assertContextualLinkRetainsMouseup();
} }
...@@ -300,20 +304,33 @@ protected function movePointerTo($selector) { ...@@ -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 * @param string $selector_type
* CSS selector. * The element selector type (CSS, XPath).
* @param string|array $selector
* The element selector.
* @param int $timeout * @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000. * (optional) Timeout in milliseconds, defaults to 10000.
* @param string $message * @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 = '') { public function assertNoElementAfterWait($selector_type, $selector, $timeout = 10000, $message = 'Element exists on the page.') {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)"; $start = microtime(TRUE);
$this->assertJsCondition($condition, $timeout, $message); $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