diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormPageCacheTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormPageCacheTest.php index 9358023d9f..4b61a81436 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormPageCacheTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormPageCacheTest.php @@ -44,17 +44,32 @@ public function testSimpleAJAXFormValue() { $this->assertEquals($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.'); $build_id_initial = $this->getFormBuildId(); - $session = $this->getSession(); // Changing the value of a select input element, triggers a AJAX request/response. + // + // The callback on the form responds with three AJAX command :- + // UpdateBuildIdCommand + // HtmlCommand + // DataCommand + $session = $this->getSession(); $session->getPage()->selectFieldOption('select', 'green'); - $this->assertSession()->assertWaitOnAjaxRequest(); + // Wait for the DOM to update. + // The HtmlCommand will update #ajax_selected_color to reflect the color change. + $green_div = $this->assertSession()->waitForElement('css', "#ajax_selected_color div:contains('green')"); + $this->assertNotNull($green_div, 'DOM update: The selected color DIV is green.'); + + // Confirm the operation of the UpdateBuildIdCommand. $build_id_first_ajax = $this->getFormBuildId(); $this->assertNotEquals($build_id_initial, $build_id_first_ajax, 'Build id is changed in the form_build_id element on first AJAX submission'); // Changing the value of a select input element, triggers a AJAX request/response. $session->getPage()->selectFieldOption('select', 'red'); - $this->assertSession()->assertWaitOnAjaxRequest(); + + // Wait for the DOM to update. + $red_div = $this->assertSession()->waitForElement('css', "#ajax_selected_color div:contains('red')"); + $this->assertNotNull($red_div, 'DOM update: The selected color DIV is red.'); + + // Confirm the operation of the UpdateBuildIdCommand. $build_id_second_ajax = $this->getFormBuildId(); $this->assertNotEquals($build_id_first_ajax, $build_id_second_ajax, 'Build id changes on subsequent AJAX submissions'); @@ -67,14 +82,22 @@ public function testSimpleAJAXFormValue() { // Changing the value of a select input element, triggers a AJAX request/response. $session->getPage()->selectFieldOption('select', 'green'); - $this->assertSession()->assertWaitOnAjaxRequest(); + + // Wait for the DOM to update. + $green_div2 = $this->assertSession()->waitForElement('css', "#ajax_selected_color div:contains('green')"); + $this->assertNotNull($green_div2, 'DOM update: After reload - the selected color DIV is green.'); + $build_id_from_cache_first_ajax = $this->getFormBuildId(); $this->assertNotEquals($build_id_from_cache_initial, $build_id_from_cache_first_ajax, 'Build id is changed in the simpletest-DOM on first AJAX submission'); $this->assertNotEquals($build_id_first_ajax, $build_id_from_cache_first_ajax, 'Build id from first user is not reused'); // Changing the value of a select input element, triggers a AJAX request/response. $session->getPage()->selectFieldOption('select', 'red'); - $this->assertSession()->assertWaitOnAjaxRequest(); + + // Wait for the DOM to update. + $red_div2 = $this->assertSession()->waitForElement('css', "#ajax_selected_color div:contains('red')"); + $this->assertNotNull($red_div2, 'DOM update: After reload - the selected color DIV is red.'); + $build_id_from_cache_second_ajax = $this->getFormBuildId(); $this->assertNotEquals($build_id_from_cache_first_ajax, $build_id_from_cache_second_ajax, 'Build id changes on subsequent AJAX submissions');