From 7e318cc0b3cf7fed856bc65489078db2145d4921 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Thu, 16 Feb 2023 08:56:04 +0000
Subject: [PATCH] Issue #3103240 by oknate, smustgrave, quietone, jungle:
 MultiFormTest not executing

---
 .../Ajax/MultiFormTest.php                      | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/MultiFormTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/MultiFormTest.php
index fbd979c4e36b..83c26e96e1a6 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/MultiFormTest.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/MultiFormTest.php
@@ -92,20 +92,21 @@ public function testMultiForm() {
     // page update, ensure the same as above.
 
     for ($i = 0; $i < 2; $i++) {
-      $forms = $page->find('xpath', $form_xpath);
+      $forms = $page->findAll('xpath', $form_xpath);
       foreach ($forms as $offset => $form) {
         $button = $form->findButton('Add another item');
         $this->assertNotNull($button, 'Add Another Item button exists');
         $button->press();
 
-        // Wait for page update.
-        $this->assertSession()->assertWaitOnAjaxRequest();
+        // Wait for field to be added with ajax.
+        $this->assertNotEmpty($page->waitFor(10, function () use ($form, $i) {
+          return $form->findField('field_ajax_test[' . ($i + 1) . '][value]');
+        }));
 
-        // After AJAX request and response page will update.
-        $page_updated = $session->getPage();
-        $field = $page_updated->findAll('xpath', '.' . $field_xpath);
-        $this->assertCount($i + 2, $field[0]->find('xpath', '.' . $field_items_xpath_suffix), 'Found the correct number of field items after an AJAX submission.');
-        $this->assertNotNull($field[0]->find('xpath', '.' . $button_xpath_suffix), 'Found the "add more" button after an AJAX submission.');
+        // After AJAX request and response verify the correct number of text
+        // fields (including title), as well as the "Add another item" button.
+        $this->assertCount($i + 3, $form->findAll('css', 'input[type="text"]'), 'Found the correct number of field items after an AJAX submission.');
+        $this->assertNotEmpty($form->findButton('Add another item'), 'Found the "add more" button after an AJAX submission.');
         $this->assertSession()->pageContainsNoDuplicateId();
       }
     }
-- 
GitLab