From 9b01841df3045f1ced9461481d33c2eea82f7fd6 Mon Sep 17 00:00:00 2001 From: LucasC Date: Fri, 22 Nov 2024 15:22:46 +0100 Subject: [PATCH] XWIKI-22680: Regression on createAndDeleteUser (#3675) * Fixed the wait condition at the end of the formFilling function * Fixed the wait condition for password change (cherry picked from commit 3d6720222bd482ef73b76b4744373231d91c79bb) --- .../test/po/ResetPasswordCompletePage.java | 3 +++ .../xwiki/test/ui/po/FormContainerElement.java | 17 +++++++++++------ .../xwiki/user/test/po/ChangePasswordPage.java | 1 + 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-pageobjects/src/main/java/org/xwiki/administration/test/po/ResetPasswordCompletePage.java b/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-pageobjects/src/main/java/org/xwiki/administration/test/po/ResetPasswordCompletePage.java index 9cb3a8dff9e8..def95f9ba371 100644 --- a/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-pageobjects/src/main/java/org/xwiki/administration/test/po/ResetPasswordCompletePage.java +++ b/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-pageobjects/src/main/java/org/xwiki/administration/test/po/ResetPasswordCompletePage.java @@ -77,6 +77,9 @@ public String getPasswordConfirmation() public void setPasswordConfirmation(String newPasswordConfirmation) { this.newPasswordConfirmationField.sendKeys(newPasswordConfirmation); + getDriver().waitUntilCondition( + driver -> !this.newPasswordConfirmationField.getAttribute("class").isEmpty() + ); } public ResetPasswordCompletePage clickSave() diff --git a/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/FormContainerElement.java b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/FormContainerElement.java index 1c8e4db7f687..ca02194dc0a5 100644 --- a/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/FormContainerElement.java +++ b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/FormContainerElement.java @@ -73,20 +73,25 @@ protected WebElement getFormElement() public void fillFieldsByName(Map valuesByNames) { - Map valuesByElements = new LinkedHashMap<>((int) (valuesByNames.size() / 0.75)); - + Map valuesByElements = new LinkedHashMap<>(); + + WebElement lastElement = null; for (String name : valuesByNames.keySet()) { - valuesByElements.put(getFormElement().findElement(By.name(name)), valuesByNames.get(name)); + lastElement = getFormElement().findElement(By.name(name)); + valuesByElements.put(lastElement, valuesByNames.get(name)); } fillFieldsByElements(valuesByElements); /* Register password confirmation is usually the last element that needs to be validated by liveValidation. This wait allows to solve a race condition between the form submission and the computation of the status of those fields. We force the status to be solved before we try anything else, especially submitting the form. + Unfortunately in Java17 we do not have lastEntry() from LinkedHashMaps, + so we use a few non optimized operations instead. + This is okay because the Map should not contain a lot of elements. */ - if (valuesByNames.containsKey("register2_password")) { - getDriver().waitUntilCondition(driver -> !getFormElement().findElement(By.name("register2_password")) - .getAttribute(CLASS_ATTRIBUTE).isEmpty()); + if(!valuesByElements.isEmpty() && lastElement != null) { + WebElement finalLastElement = lastElement; + getDriver().waitUntilCondition(driver -> !finalLastElement.getAttribute(CLASS_ATTRIBUTE).isEmpty()); } } diff --git a/xwiki-platform-core/xwiki-platform-user/xwiki-platform-user-profile/xwiki-platform-user-profile-test/xwiki-platform-user-profile-test-pageobjects/src/main/java/org/xwiki/user/test/po/ChangePasswordPage.java b/xwiki-platform-core/xwiki-platform-user/xwiki-platform-user-profile/xwiki-platform-user-profile-test/xwiki-platform-user-profile-test-pageobjects/src/main/java/org/xwiki/user/test/po/ChangePasswordPage.java index a9f1d7472511..5ed2a5b2587d 100644 --- a/xwiki-platform-core/xwiki-platform-user/xwiki-platform-user-profile/xwiki-platform-user-profile-test/xwiki-platform-user-profile-test-pageobjects/src/main/java/org/xwiki/user/test/po/ChangePasswordPage.java +++ b/xwiki-platform-core/xwiki-platform-user/xwiki-platform-user-profile/xwiki-platform-user-profile-test/xwiki-platform-user-profile-test-pageobjects/src/main/java/org/xwiki/user/test/po/ChangePasswordPage.java @@ -82,6 +82,7 @@ public void changePassword(String originalPassword, String password, String pass this.password1.sendKeys(password); this.password2.clear(); this.password2.sendKeys(password2); + getDriver().waitUntilElementHasNonEmptyAttributeValue(By.xpath("//input[@id='xwikipassword2']"),"class"); } /**