Adding retry when clicking on rememberMe checkbox on the loginPage during tests
closes #32476 closes #32677 closes #32767 closes #33132 closes #32550 Signed-off-by: mposolda <mposolda@gmail.com>
This commit is contained in:
parent
64e096d89c
commit
cb5c510c49
2 changed files with 26 additions and 4 deletions
|
@ -22,6 +22,7 @@ import org.junit.Assert;
|
|||
import org.keycloak.common.util.Retry;
|
||||
import org.keycloak.testsuite.util.DroneUtils;
|
||||
import org.keycloak.testsuite.util.OAuthClient;
|
||||
import org.keycloak.testsuite.util.UIUtils;
|
||||
import org.keycloak.testsuite.util.WaitUtils;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.Keys;
|
||||
|
@ -247,10 +248,7 @@ public class LoginPage extends LanguageComboboxAwarePage {
|
|||
}
|
||||
|
||||
public void setRememberMe(boolean enable) {
|
||||
boolean current = rememberMe.isSelected();
|
||||
if (current != enable) {
|
||||
rememberMe.click();
|
||||
}
|
||||
UIUtils.switchCheckbox(rememberMe, enable);
|
||||
}
|
||||
|
||||
public boolean isRememberMeChecked() {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.keycloak.testsuite.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Assert;
|
||||
import org.keycloak.common.util.Retry;
|
||||
import org.keycloak.testsuite.page.AbstractPatternFlyAlert;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.JavascriptExecutor;
|
||||
|
@ -100,6 +102,28 @@ public final class UIUtils {
|
|||
performOperationWithPageReload(element::click);
|
||||
}
|
||||
|
||||
/**
|
||||
* The method switches the checkbox to the expected state.
|
||||
*
|
||||
* It looks that since chrome 128, the single click sometimes does
|
||||
* not work (See also similar issue {@link #clickLink(WebElement)}, so it is possible repeated multiple times until it reach
|
||||
* the desired state
|
||||
*
|
||||
* @param checkbox Checkbox element to enable or disable
|
||||
* @param enable If true, the checkbox should be switched to enabled (checked). If false, the checkbox should be switched to disabled (unchecked)
|
||||
*/
|
||||
public static void switchCheckbox(WebElement checkbox, boolean enable) {
|
||||
int maxAttempts = 4;
|
||||
|
||||
Retry.execute(() -> {
|
||||
boolean current = checkbox.isSelected();
|
||||
if (current != enable) {
|
||||
UIUtils.click(checkbox);
|
||||
Assert.assertNotEquals("Checkbox " + checkbox + " is still in the state " + current + " after click.", current, checkbox.isSelected());
|
||||
}
|
||||
}, maxAttempts, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is as an alternative for {@link #clickLink(WebElement)} and should be used in situations where we can't use
|
||||
* {@link WaitUtils#waitForPageToLoad()}. This is because {@link WaitUtils#waitForPageToLoad()} would wait until the
|
||||
|
|
Loading…
Reference in a new issue