Skip to content

Commit

Permalink
XWIKI-22680: Regression on createAndDeleteUser (#3675)
Browse files Browse the repository at this point in the history
* Fixed the wait condition at the end of the formFilling function
* Fixed the wait condition for password change

(cherry picked from commit 3d67202)
  • Loading branch information
Sereza7 authored and github-actions[bot] committed Nov 22, 2024
1 parent 6ef5a0b commit 9b01841
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,25 @@ protected WebElement getFormElement()

public void fillFieldsByName(Map<String, String> valuesByNames)
{
Map<WebElement, String> valuesByElements = new LinkedHashMap<>((int) (valuesByNames.size() / 0.75));

Map<WebElement, String> 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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/**
Expand Down

0 comments on commit 9b01841

Please sign in to comment.