diff --git a/core/modules/system/tests/modules/dialog_test/dialog_test.info.yml b/core/modules/system/tests/modules/dialog_test/dialog_test.info.yml
new file mode 100644
index 0000000..408e4bc
--- /dev/null
+++ b/core/modules/system/tests/modules/dialog_test/dialog_test.info.yml
@@ -0,0 +1,6 @@
+name: 'Dialog test module'
+type: module
+description: 'Module for the dialog related tests.'
+package: Testing
+version: VERSION
+core: 8.x
diff --git a/core/modules/system/tests/modules/dialog_test/dialog_test.libraries.yml b/core/modules/system/tests/modules/dialog_test/dialog_test.libraries.yml
new file mode 100644
index 0000000..62d4ea1
--- /dev/null
+++ b/core/modules/system/tests/modules/dialog_test/dialog_test.libraries.yml
@@ -0,0 +1,7 @@
+dialog_debug:
+  version: VERSION
+  js:
+    js/dialog.debug.js: {}
+  dependencies:
+    - core/jquery
+    - core/drupal
diff --git a/core/modules/system/tests/modules/dialog_test/dialog_test.module b/core/modules/system/tests/modules/dialog_test/dialog_test.module
new file mode 100644
index 0000000..4fb516b
--- /dev/null
+++ b/core/modules/system/tests/modules/dialog_test/dialog_test.module
@@ -0,0 +1,8 @@
+<?php
+
+/**
+* Implements hook_page_attachments().
+*/
+function dialog_test_page_attachments(array &$page) {
+  $page['#attached']['library'][] = 'dialog_test/dialog_debug';
+}
diff --git a/core/modules/system/tests/modules/dialog_test/js/dialog.debug.js b/core/modules/system/tests/modules/dialog_test/js/dialog.debug.js
new file mode 100644
index 0000000..de3de90
--- /dev/null
+++ b/core/modules/system/tests/modules/dialog_test/js/dialog.debug.js
@@ -0,0 +1,23 @@
+/**
+ * @file
+ *  Testing behavior for JSWebAssertTest.
+ */
+
+(function ($, Drupal, drupalSettings) {
+
+  'use strict';
+
+  Drupal.dialog_debug = {
+    has_open_dialog: false
+  };
+
+  // Register the dialog opened by listening to the dialogContentResize event.
+  $('#drupal-modal').on('dialogContentResize', function (event) {
+    Drupal.dialog_debug.has_open_dialog = true;
+  });
+  // Register the beforecreate and afterclose to indicate the dialog has been closed.
+  $(window).on('dialog:beforecreate dialog:afterclose', function () {
+    Drupal.dialog_debug.has_open_dialog = false;
+  });
+
+})(jQuery, Drupal, drupalSettings);
diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php
index e48487a..10c842c 100644
--- a/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php
+++ b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\views_ui\FunctionalJavascript;
 
 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
+use Drupal\FunctionalTests\AssertDialogTrait;
 
 /**
  * Tests the View UI filter criteria group dialog.
@@ -11,10 +12,12 @@
  */
 class FilterCriteriaTest extends JavascriptTestBase {
 
+  use AssertDialogTrait;
+
   /**
    * {@inheritdoc}
    */
-  public static $modules = ['node', 'views', 'views_ui'];
+  public static $modules = ['node', 'views', 'views_ui', 'dialog_test'];
 
   /**
    * {@inheritdoc}
@@ -48,29 +51,37 @@ public function testFilterCriteriaDialog() {
     $add_link = $page->findById('views-rearrange-filter');
     $this->assertTrue($add_link->isVisible(), 'And/Or Rearrange button found.');
     $add_link->click();
-    $assert_session->assertWaitOnAjaxRequest();
+
+    // Wait for the dialog to open.
+    $this->waitForDialog();
 
     // Add a new filter group.
     $create_new_filter_group = $page->findById('views-add-group-link');
     $this->assertTrue($create_new_filter_group->isVisible(), 'Add group link found.');
     $create_new_filter_group->click();
-    $assert_session->assertWaitOnAjaxRequest();
 
     // Assert the existence of the new filter group by checking the remove group
     // link.
-    $remove_link = $page->findLink('Remove group');
+    $remove_link = $assert_session->waitForElementVisible('named_exact', array(
+      'link',
+      'Remove group'
+    ));
+
     $this->assertTrue($remove_link->isVisible(), 'New group found.');
 
     // Remove the group again and assert the group is not present anymore.
     $remove_link->click();
-    $assert_session->assertWaitOnAjaxRequest();
-    $remove_link = $page->findLink('Remove group');
-    $this->assertEmpty($remove_link, 'Remove button not available');
+
+    $result = $page->waitFor(10, function() use($page) {
+      $remove_link = $page->findLink('Remove group');
+      return empty($remove_link);
+    });
+
+    $this->assertTrue($result, 'Remove button not available');
 
     // Checks that the admin summary is not double escaped.
     $this->drupalGet('admin/structure/views/view/who_s_online');
     $page = $this->getSession()->getPage();
     $this->assertNotNull($page->findLink('User: Last access (>= -15 minutes)'));
   }
-
 }
diff --git a/core/tests/Drupal/FunctionalTests/AssertDialogTrait.php b/core/tests/Drupal/FunctionalTests/AssertDialogTrait.php
new file mode 100644
index 0000000..9a4e463
--- /dev/null
+++ b/core/tests/Drupal/FunctionalTests/AssertDialogTrait.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Drupal\FunctionalTests;
+
+/**
+ * Provides methods for assertions in dialogs.
+ */
+trait AssertDialogTrait {
+
+  /**
+   * Wait for the dialog to be opened.
+   *
+   * @param int $timeout
+   *   (Optional) Timeout in milliseconds, defaults to 10000.
+   */
+  protected function waitForDialog($timeout = 10000) {
+    $this->asserTrue(in_array('dialog_test', $this->modules), 'The dialog_test module is required for this assertion.');
+
+    $condition = 'Drupal.dialog_debug.has_open_dialog == true';
+    $this->getSession()->wait($timeout, $condition);
+  }
+
+}
