mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-10 15:32:05 -03:30
Manage exceptions in waitForPageToLoad for chrome error in version 132
Closes #36781 Closes #36782 Closes #36902 Signed-off-by: rmartinc <rmartinc@redhat.com> (cherry picked from commit efbeb8caa6170cfc870ac99757cdaedb22dcbbcc)
This commit is contained in:
parent
da2fceb699
commit
f76b7e80a7
@ -2,7 +2,6 @@ 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;
|
||||
@ -82,15 +81,41 @@ public final class UIUtils {
|
||||
* @param element The element to click
|
||||
*/
|
||||
public static void clickLink(WebElement element) {
|
||||
clickElement(element, Keys.ENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same than clickLink but it does not perform any wait after clicking or sending the
|
||||
* enter key.
|
||||
*
|
||||
* @param element The element to click
|
||||
*/
|
||||
public static void clickLinkWithoutWait(WebElement element) {
|
||||
clickLinkWithoutWait(element, Keys.ENTER);
|
||||
}
|
||||
|
||||
private static void clickElement(WebElement element, CharSequence key) {
|
||||
WebDriver driver = getCurrentDriver();
|
||||
|
||||
waitUntilElement(element).is().clickable();
|
||||
|
||||
performOperationWithPageReload(BrowserDriverUtil.isDriverChrome(driver)
|
||||
? () -> element.sendKeys(Keys.ENTER)
|
||||
? () -> element.sendKeys(key)
|
||||
: element::click);
|
||||
}
|
||||
|
||||
private static void clickLinkWithoutWait(WebElement element, CharSequence key) {
|
||||
WebDriver driver = getCurrentDriver();
|
||||
|
||||
waitUntilElement(element).is().clickable();
|
||||
|
||||
if (BrowserDriverUtil.isDriverChrome(driver)) {
|
||||
element.sendKeys(key);
|
||||
} else {
|
||||
element.click();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The method executes click in the element. This method always uses click and
|
||||
* is not emulated by key pressing in chrome.
|
||||
@ -113,15 +138,11 @@ public final class UIUtils {
|
||||
* @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);
|
||||
boolean current = checkbox.isSelected();
|
||||
if (current != enable) {
|
||||
clickElement(checkbox, Keys.SPACE);
|
||||
Assert.assertNotEquals("Checkbox " + checkbox + " is still in the state " + current + " after click.", current, checkbox.isSelected());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -129,19 +129,19 @@ public final class WaitUtils {
|
||||
return; // not needed
|
||||
}
|
||||
|
||||
String currentUrl = null;
|
||||
|
||||
// Ensure the URL is "stable", i.e. is not changing anymore; if it'd changing, some redirects are probably still in progress
|
||||
for (int maxRedirects = 4; maxRedirects > 0; maxRedirects--) {
|
||||
currentUrl = driver.getCurrentUrl();
|
||||
FluentWait<WebDriver> wait = new FluentWait<>(driver).withTimeout(Duration.ofMillis(250));
|
||||
try {
|
||||
String currentUrl = driver.getCurrentUrl();
|
||||
FluentWait<WebDriver> wait = new FluentWait<>(driver).withTimeout(Duration.ofMillis(250));
|
||||
wait.until(not(urlToBe(currentUrl)));
|
||||
}
|
||||
catch (TimeoutException e) {
|
||||
} catch (TimeoutException e) {
|
||||
if (driver.getPageSource() != null) {
|
||||
break; // URL has not changed recently - ok, the URL is stable and page is current
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warnf("Unknown exception thrown waiting stabilization of the URL: %s", e.getMessage());
|
||||
pause(250);
|
||||
}
|
||||
if (maxRedirects == 1) {
|
||||
log.warn("URL seems unstable! (Some redirect are probably still in progress)");
|
||||
|
||||
@ -19,6 +19,7 @@ package org.keycloak.testsuite.webauthn.pages;
|
||||
|
||||
import org.jboss.arquillian.graphene.page.Page;
|
||||
import org.keycloak.testsuite.pages.LanguageComboboxAwarePage;
|
||||
import org.keycloak.testsuite.util.UIUtils;
|
||||
import org.keycloak.testsuite.util.WaitUtils;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
@ -43,7 +44,7 @@ public class WebAuthnLoginPage extends LanguageComboboxAwarePage {
|
||||
|
||||
public void clickAuthenticate() {
|
||||
WaitUtils.waitUntilElement(authenticateButton).is().clickable();
|
||||
authenticateButton.click();
|
||||
UIUtils.clickLink(authenticateButton);
|
||||
}
|
||||
|
||||
public boolean isCurrent() {
|
||||
|
||||
@ -19,6 +19,7 @@ package org.keycloak.testsuite.webauthn.pages;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.keycloak.testsuite.pages.LogoutSessionsPage;
|
||||
import org.keycloak.testsuite.util.UIUtils;
|
||||
import org.keycloak.testsuite.util.WaitUtils;
|
||||
import org.openqa.selenium.Alert;
|
||||
import org.openqa.selenium.By;
|
||||
@ -56,14 +57,12 @@ public class WebAuthnRegisterPage extends LogoutSessionsPage {
|
||||
private WebElement formTitle;
|
||||
|
||||
public void clickRegister() {
|
||||
WaitUtils.waitUntilElement(registerButton).is().clickable();
|
||||
registerButton.click();
|
||||
UIUtils.clickLinkWithoutWait(registerButton);
|
||||
}
|
||||
|
||||
public void cancelAIA() {
|
||||
assertThat("It only works with AIA", isAIA(), CoreMatchers.is(true));
|
||||
WaitUtils.waitUntilElement(cancelAIAButton).is().clickable();
|
||||
cancelAIAButton.click();
|
||||
UIUtils.clickLink(cancelAIAButton);
|
||||
}
|
||||
|
||||
public void registerWebAuthnCredential(String authenticatorLabel) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user