Issue #3056536 by alexpott, tedbow: LayoutBuilderDisableInteractionsTest randomly fails
parent
a84d05f2bf
commit
e46168f2dc
|
|
@ -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 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase {
|
||||||
'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 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase {
|
||||||
* 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 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase {
|
||||||
$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 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase {
|
||||||
$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 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase {
|
||||||
$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 @@ 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
|
* @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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue