Unverified Commit 9a11de65 authored by alexpott's avatar alexpott

Issue #2892440 by bnjmnm, tedbow, alexpott, Krzysztof Domański, Lendude:...

Issue #2892440 by bnjmnm, tedbow, alexpott, Krzysztof Domański, Lendude: Provide helper test method to wait for an element to be removed from the page
parent 2be8f419
......@@ -71,7 +71,7 @@ public function testValidationMessage() {
$block_css_locator = '#layout-builder .block-system-powered-by-block';
$this->assertNotEmpty($assert_session->waitForElementVisible('css', $block_css_locator));
$this->waitForNoElement('#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->assertWaitOnAjaxRequest();
$this->drupalGet($this->getUrl());
$this->clickElementWhenClickable($page->findButton('Save layout'));
......@@ -87,21 +87,6 @@ public function testValidationMessage() {
$this->assertMessagesDisplayed();
}
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
}
/**
* Asserts that the validation messages are shown correctly.
*/
......
......@@ -78,8 +78,7 @@ public function testContentPreviewToggle() {
$page->uncheckField('layout-builder-content-preview');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '.layout-builder-block__content-preview-placeholder-label'));
// Wait for preview content hide() to complete.
$this->waitForNoElement('[data-layout-content-preview-placeholder-label] .field--name-body:visible');
// Confirm that block content is not on page.
$assert_session->pageTextNotContains($content_preview_body_text);
$this->assertContextualLinks();
......@@ -124,7 +123,7 @@ protected function assertContextualLinks() {
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertNotEmpty($this->assertSession()->waitForButton('Close'));
$page->pressButton('Close');
$this->waitForNoElement('#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
}
/**
......@@ -147,19 +146,4 @@ protected function assertOrderInPage(array $items) {
$this->assertCount(count($items), $blocks_with_expected_text);
}
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
}
}
......@@ -110,8 +110,9 @@ protected function addBlock($block_name) {
$this->assertNotEmpty($assert_session->waitForElementVisible('css', "#drupal-off-canvas a:contains('$block_name')"));
$page->clickLink($block_name);
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '[data-drupal-selector=\'edit-actions-submit\']'));
$page->pressButton('Add block');
$this->waitForNoElement('#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->assertWaitOnAjaxRequest();
}
......@@ -148,19 +149,4 @@ protected function assertCorrectContextualLinksInNode() {
$this->assertNotEmpty($page->findAll('css', '.layout-content [data-contextual-id]'));
}
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
}
}
......@@ -116,8 +116,8 @@ protected function removeInlineBlockFromLayout() {
$assert_session->waitForElement('css', "#drupal-off-canvas input[value='Remove']");
$assert_session->assertWaitOnAjaxRequest();
$page->find('css', '#drupal-off-canvas')->pressButton('Remove');
$this->waitForNoElement('#drupal-off-canvas');
$this->waitForNoElement(static::INLINE_BLOCK_LOCATOR);
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', static::INLINE_BLOCK_LOCATOR);
$assert_session->assertWaitOnAjaxRequest();
$assert_session->pageTextNotContains($block_text);
}
......@@ -167,7 +167,7 @@ protected function configureInlineBlock($old_body, $new_body, $block_css_locator
$this->assertSame($old_body, $textarea->getValue());
$textarea->setValue($new_body);
$page->pressButton('Update');
$this->waitForNoElement('#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->assertWaitOnAjaxRequest();
$this->assertDialogClosedAndTextVisible($new_body);
}
......@@ -180,9 +180,11 @@ protected function configureInlineBlock($old_body, $new_body, $block_css_locator
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
* @deprecated in Drupal 8.8.x, will be removed before Drupal 9.0.0. Use
* Drupal\FunctionalJavascriptTests\JSWebAssert::assertNoElementAfterWait()
*/
protected function waitForNoElement($selector, $timeout = 10000) {
@trigger_error('::waitForNoElement is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use \Drupal\FunctionalJavascriptTests\JSWebAssert::assertNoElementAfterWait() instead.', E_USER_DEPRECATED);
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
}
......@@ -197,7 +199,7 @@ protected function waitForNoElement($selector, $timeout = 10000) {
*/
protected function assertDialogClosedAndTextVisible($text, $css_locator = NULL) {
$assert_session = $this->assertSession();
$this->waitForNoElement('#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->assertWaitOnAjaxRequest();
$assert_session->elementNotExists('css', '#drupal-off-canvas');
if ($css_locator) {
......
......@@ -3,7 +3,6 @@
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;
......@@ -206,7 +205,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('css', '#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
// Run the steps a second time after closing dialog, which reverses the
// order that behaviors.layoutBuilderDisableInteractiveElements and
......@@ -214,7 +213,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('css', '#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$this->assertContextualLinkRetainsMouseup();
}
......@@ -303,34 +302,4 @@ protected function movePointerTo($selector) {
$driver_session->moveto(['element' => $element->getID()]);
}
/**
* Asserts that no matching element exists on the page after a wait.
*
* @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) The exception message.
*
* @throws \Behat\Mink\Exception\ElementHtmlException
* When an element still exists on the page.
*/
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);
}
}
......@@ -125,7 +125,7 @@ public function testLayoutBuilderUi() {
// Save the new block, and ensure it is displayed on the page.
$page->pressButton('Add block');
$assert_session->assertWaitOnAjaxRequest();
$this->assertNoElementAfterWait('#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->addressEquals($layout_url);
$assert_session->pageTextContains('Powered by Drupal');
$assert_session->pageTextContains('This is the label');
......@@ -158,7 +158,7 @@ public function testLayoutBuilderUi() {
$page->pressButton('Add section');
$assert_session->assertWaitOnAjaxRequest();
$this->assertNoElementAfterWait('.layout__region--second .block-system-powered-by-block');
$assert_session->assertNoElementAfterWait('css', '.layout__region--second .block-system-powered-by-block');
$assert_session->elementTextNotContains('css', '.layout__region--second', 'Powered by Drupal');
// Drag the block to a region in different section.
......@@ -190,7 +190,7 @@ public function testLayoutBuilderUi() {
$page->fillField('settings[label]', 'This is the new label');
$page->pressButton('Update');
$assert_session->assertWaitOnAjaxRequest();
$this->assertNoElementAfterWait('#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->addressEquals($layout_url);
$assert_session->pageTextContains('Powered by Drupal');
......@@ -204,7 +204,7 @@ public function testLayoutBuilderUi() {
$assert_session->pageTextContains('This action cannot be undone.');
$page->pressButton('Remove');
$assert_session->assertWaitOnAjaxRequest();
$this->assertNoElementAfterWait('#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->pageTextNotContains('Powered by Drupal');
$assert_session->linkExists('Add block');
......@@ -296,7 +296,7 @@ public function testConfigurableLayoutSections() {
$page->pressButton('Add section');
$assert_session->assertWaitOnAjaxRequest();
$this->assertNoElementAfterWait('#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->pageTextContains('Default');
$assert_session->linkExists('Add block');
......@@ -307,7 +307,7 @@ public function testConfigurableLayoutSections() {
$page->fillField('layout_settings[setting_1]', 'Test setting value');
$page->pressButton('Update');
$assert_session->assertWaitOnAjaxRequest();
$this->assertNoElementAfterWait('#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->pageTextContains('Test setting value');
$this->assertPageNotReloaded();
}
......@@ -350,7 +350,7 @@ public function testLayoutNoDialog() {
'region' => 'content',
'plugin_id' => 'system_powered_by_block',
]));
$this->assertNoElementAfterWait('#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$page->fillField('settings[label]', 'The block label');
$page->fillField('settings[label_display]', TRUE);
$page->pressButton('Add block');
......@@ -372,28 +372,6 @@ public function testLayoutNoDialog() {
$assert_session->linkNotExists('Add block');
}
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
* @param string $message
* (optional) Custom message to display with the assertion.
*
* @todo: Remove after https://www.drupal.org/project/drupal/issues/2892440
*/
public function assertNoElementAfterWait($selector, $timeout = 10000, $message = '') {
$page = $this->getSession()->getPage();
if ($message === '') {
$message = "Element '$selector' was not on the page after wait.";
}
$this->assertTrue($page->waitFor($timeout / 1000, function () use ($page, $selector) {
return empty($page->find('css', $selector));
}), $message);
}
/**
* {@inheritdoc}
*
......
......@@ -254,23 +254,10 @@ private function assertHighlightedElement($selector) {
* Waits for the dialog to close and confirms no highlights are present.
*/
private function assertHighlightNotExists() {
$this->waitForNoElement('#drupal-off-canvas');
$this->waitForNoElement('.is-layout-builder-highlighted');
}
$assert_session = $this->assertSession();
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '.is-layout-builder-highlighted');
}
}
......@@ -83,10 +83,10 @@ protected function setUp() {
$this->assertNotEmpty($assert_session->waitForElementVisible('css', 'input[value="Add block"]'));
$assert_session->assertWaitOnAjaxRequest();
$page->pressButton('Add block');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', $first_region_block_locator));
// Ensure the request has completed before the test starts.
$this->waitForNoElement('#drupal-off-canvas');
$assert_session->assertWaitOnAjaxRequest();
}
......@@ -152,21 +152,6 @@ protected function assertBlockTable(array $expected_block_labels) {
}
}
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
}
/**
* Moves a block in the draggable table.
*
......@@ -221,7 +206,7 @@ protected function assertRegionBlocksOrder($section_delta, $region, array $expec
$assert_session = $this->assertSession();
$assert_session->assertWaitOnAjaxRequest();
$this->waitForNoElement('#drupal-off-canvas');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$region_selector = "[data-layout-delta=\"$section_delta\"] [data-region=\"$region\"]";
......
......@@ -101,25 +101,10 @@ public function testWidthChange() {
$this->clickLink('Remove section');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas input[type="submit"][value="Remove"]'));
$page->pressButton('Remove');
$this->waitForNoElement(".$width_class");
$assert_session->assertNoElementAfterWait('css', ".$width_class");
}
}
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
}
/**
* Asserts the width class is applied to the first section.
*
......
......@@ -92,22 +92,9 @@ public function testFieldWithCkeditor() {
// Wait and click by "Save" button after body field was changed.
$this->assertSession()->waitForElementVisible('css', '.quickedit-toolgroup.ops [type="submit"][aria-hidden="false"]')->click();
// Wait until the save occurs and the editor UI disappears.
$this->waitForNoElement('.cke_button.cke_button__blockquote');
$this->assertSession()->assertNoElementAfterWait('css', '.cke_button.cke_button__blockquote');
// Ensure that the changes take effect.
$assert->responseMatches("|<blockquote>\s*$body_value\s*</blockquote>|");
}
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
}
}
......@@ -79,14 +79,14 @@ protected function doTestBlocks($theme, $block_plugin, $new_page_text, $element_
if ($element = $page->find('css', "#toolbar-administration a.is-active")) {
// If a tray was open from page load close it.
$element->click();
$this->waitForNoElement("#toolbar-administration a.is-active");
$web_assert->assertNoElementAfterWait('css', "#toolbar-administration a.is-active");
}
$page->find('css', $toolbar_item)->click();
$this->assertElementVisibleAfterWait('css', "{$toolbar_item}.is-active");
}
$this->enableEditMode();
if (isset($toolbar_item)) {
$this->waitForNoElement("{$toolbar_item}.is-active");
$web_assert->assertNoElementAfterWait('css', "{$toolbar_item}.is-active");
}
$this->openBlockForm($block_selector);
switch ($block_plugin) {
......@@ -144,7 +144,7 @@ protected function doTestBlocks($theme, $block_plugin, $new_page_text, $element_
$this->getSession()->getPage()->find('css', static::TOOLBAR_EDIT_LINK_SELECTOR)->mouseOver();
$this->assertEditModeDisabled();
$this->assertNotEmpty($web_assert->waitForElement('css', '#drupal-live-announce:contains(Exited edit mode)'));
$this->waitForNoElement('.contextual-toolbar-tab button:contains(Editing)');
$web_assert->assertNoElementAfterWait('css', '.contextual-toolbar-tab button:contains(Editing)');
$web_assert->elementAttributeNotContains('css', '.dialog-off-canvas-main-canvas', 'class', 'js-settings-tray-edit-mode');
// Clean up test data so each test does not impact the next.
......
/**
* @file
* Testing behavior for JSWebAssertTest.
*/
(($, Drupal) => {
/**
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Makes changes in the DOM to be able to test the completion of AJAX in assertWaitOnAjaxRequest.
*/
Drupal.behaviors.js_webassert_test_wait_for_ajax_request = {
attach() {
$('#edit-test-assert-no-element-after-wait-pass').on('click', e => {
e.preventDefault();
setTimeout(() => {
$('#edit-test-assert-no-element-after-wait-pass').remove();
}, 500);
});
$('#edit-test-assert-no-element-after-wait-fail').on('click', e => {
e.preventDefault();
setTimeout(() => {
$('#edit-test-assert-no-element-after-wait-fail').remove();
}, 2000);
});
},
};
})(jQuery, Drupal);
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/
(function ($, Drupal) {
Drupal.behaviors.js_webassert_test_wait_for_ajax_request = {
attach: function attach() {
$('#edit-test-assert-no-element-after-wait-pass').on('click', function (e) {
e.preventDefault();
setTimeout(function () {
$('#edit-test-assert-no-element-after-wait-pass').remove();
}, 500);
});
$('#edit-test-assert-no-element-after-wait-fail').on('click', function (e) {
e.preventDefault();
setTimeout(function () {
$('#edit-test-assert-no-element-after-wait-fail').remove();
}, 2000);
});
}
};
})(jQuery, Drupal);
\ No newline at end of file
......@@ -12,3 +12,11 @@ wait_for_element:
dependencies:
- core/jquery
- core/drupal
no_element_after_wait:
version: VERSION
js:
js/js_webassert_test.no_element_after_wait.js: {}
dependencies:
- core/jquery
- core/drupal
......@@ -113,6 +113,22 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'wrapper' => 'js_webassert_test_form_wrapper',
],
];
// Button to test the assertNoElementAfterWait() assertion, will pass.
$form['test_assert_no_element_after_wait_pass'] = [
'#type' => 'submit',
'#value' => $this->t('Test assertNoElementAfterWait: pass'),
'#button_type' => 'primary',
'#attached' => ['library' => 'js_webassert_test/no_element_after_wait'],
];
// Button to test the assertNoElementAfterWait() assertion, will fail.
$form['test_assert_no_element_after_wait_fail'] = [
'#type' => 'submit',
'#value' => $this->t('Test assertNoElementAfterWait: fail'),
'#button_type' => 'primary',
];
return $form;
}
......
......@@ -156,7 +156,7 @@ protected function assertOffCanvasDialog($link_index, $position) {
// Click the first test like that should open the page.
$page->clickLink($link_text);
if ($this->lastDialogClass) {
$this->waitForNoElement('.' . $this->lastDialogClass);
$web_assert->assertNoElementAfterWait('css', '.' . $this->lastDialogClass);
}
$this->waitForOffCanvasToOpen($position);
$this->lastDialogClass = "$position-$link_index";
......
......@@ -41,7 +41,7 @@ protected function assertPageLoadComplete() {
* @todo Move this function to https://www.drupal.org/node/2821724.
*/
protected function assertAllContextualLinksLoaded() {
$this->waitForNoElement('[data-contextual-id]:empty');
$this->assertSession()->assertNoElementAfterWait('css', '[data-contextual-id]:empty');
}
/**
......@@ -81,7 +81,7 @@ protected function waitForOffCanvasToOpen($position = 'side') {
* Waits for off-canvas dialog to close.
*/
protected function waitForOffCanvasToClose() {
$this->waitForNoElement('#drupal-off-canvas');
$this->assertSession()->assertNoElementAfterWait('css', '#drupal-off-canvas');
}
/**
......@@ -103,25 +103,12 @@ protected function getOffCanvasDialog() {
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
* @deprecated in Drupal 8.8.x, will be removed before Drupal 9.0.0. Use
* Drupal\FunctionalJavascriptTests\JSWebAssert::assertNoElementAfterWait()
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$start = microtime(TRUE);
$end = $start + ($timeout / 1000);
$page = $this->getSession()->getPage();
do {
$result = $page->find('css', $selector);
if (empty($result)) {
return;
}
usleep(100000);
} while (microtime(TRUE) < $end);
$this->assertEmpty($result, 'Element was not on the page after wait.');
@trigger_error('::waitForNoElement is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use \Drupal\FunctionalJavascriptTests\JSWebAssert::assertNoElementAfterWait() instead.', E_USER_DEPRECATED);
$this->assertSession()->assertNoElementAfterWait('css', $selector, $timeout);
}
/**
......
......@@ -59,7 +59,7 @@ public function testThemingThrobberElement() {
JS;
$this->drupalGet('admin/structure/views/view/content');
$this->waitForNoElement('.ajax-progress-fullscreen');
$web_assert->assertNoElementAfterWait('css', '.ajax-progress-fullscreen');
// Test theming fullscreen throbber.
$session->executeScript($custom_ajax_progress_indicator_fullscreen);
......@@ -67,7 +67,7 @@ public function testThemingThrobberElement() {
$page->clickLink('Content: Published (grouped)');
$this->assertNotNull($web_assert->waitForElement('css', '.custom-ajax-progress-fullscreen'), 'Custom ajaxProgressIndicatorFullscreen.');
hold_test_response(FALSE);
$this->waitForNoElement('.custom-ajax-progress-fullscreen');
$web_assert->assertNoElementAfterWait('css', '.custom-ajax-progress-fullscreen');
// Test theming throbber message.
$web_assert->waitForElementVisible('css', '[data-drupal-selector="edit-options-group-info-add-group"]');
......@@ -76,7 +76,7 @@ public function testThemingThrobberElement() {
$page->pressButton('Add another item');
$this->assertNotNull($web_assert->waitForElement('css', '.ajax-progress-throbber .custom-ajax-progress-message'), 'Custom ajaxProgressMessage.');
hold_test_response(FALSE);
$this->waitForNoElement('.ajax-progress-throbber');
$web_assert->assertNoElementAfterWait('css', '.ajax-progress-throbber');
// Test theming throbber.
$web_assert->waitForElementVisible('css', '[data-drupal-selector="edit-options-group-info-group-items-3-title"]');
......@@ -85,22 +85,7 @@ public function testThemingThrobberElement() {
$page->pressButton('Add another item');
$this->assertNotNull($web_assert->waitForElement('css', '.custom-ajax-progress-throbber'), 'Custom ajaxProgressThrobber.');
hold_test_response(FALSE);
$this->waitForNoElement('.custom-ajax-progress-throbber');
}
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
$web_assert->assertNoElementAfterWait('css', '.custom-ajax-progress-throbber');
}
}
......@@ -387,4 +387,35 @@ function t(r, lx, ly) {
return $this->session->evaluateScript($full_javascript_visibility_test);
}
/**
* Asserts that no matching element exists on the page after a wait.
*
* @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) The exception message.
*
* @throws \Behat\Mink\Exception\ElementHtmlException
* When an element still exists on the page.
*/
public function assertNoElementAfterWait($selector_type, $selector, $timeout = 10000, $message = 'Element exists on the page.') {
$start = microtime(TRUE);
$end = $start + ($timeout / 1000);
$page = $this->session->getPage();
do {
$node = $page->find($selector_type, $selector);
if (empty($node)) {
return;
}
usleep(100000);
} while (microtime(TRUE) < $end);