From 4f66087bf493a572b6486d8bb05d5844554d75ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Barto=C5=A1?= Date: Mon, 6 Dec 2021 19:21:22 +0100 Subject: [PATCH] Fix for WebAuthn tests --- .../testsuite/page/AbstractPatternFlyAlert.java | 16 ++++++++++++---- .../webauthn/pages/WebAuthnPolicyPage.java | 10 +++++++--- .../AbstractWebAuthnPolicySettingsTest.java | 6 ++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/page/AbstractPatternFlyAlert.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/page/AbstractPatternFlyAlert.java index 9b5079180c..90e653008e 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/page/AbstractPatternFlyAlert.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/page/AbstractPatternFlyAlert.java @@ -20,10 +20,10 @@ package org.keycloak.testsuite.page; import org.jboss.arquillian.drone.api.annotation.Drone; import org.jboss.logging.Logger; import org.openqa.selenium.By; -import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; @@ -56,9 +56,17 @@ public abstract class AbstractPatternFlyAlert { } public static void waitUntilDisplayed() { - new WebDriverWait(getCurrentDriver(), PAGELOAD_TIMEOUT_MILLIS / 1000).until( - ExpectedConditions.visibilityOfElementLocated(By.className(ALERT_CLASS_NAME)) - ); + waitUntilDisplayedOrHidden(true); + } + + public static void waitUntilHidden() { + waitUntilDisplayedOrHidden(false); + } + + private static void waitUntilDisplayedOrHidden(boolean displayed) { + ExpectedCondition condition = ExpectedConditions.visibilityOfElementLocated(By.className(ALERT_CLASS_NAME)); + condition = displayed ? condition : ExpectedConditions.not(condition); + new WebDriverWait(getCurrentDriver(), PAGELOAD_TIMEOUT_MILLIS / 1000).until(condition); } public String getText() { diff --git a/testsuite/integration-arquillian/tests/other/webauthn/src/main/java/org/keycloak/testsuite/webauthn/pages/WebAuthnPolicyPage.java b/testsuite/integration-arquillian/tests/other/webauthn/src/main/java/org/keycloak/testsuite/webauthn/pages/WebAuthnPolicyPage.java index 725c5f75ca..e226beb2eb 100644 --- a/testsuite/integration-arquillian/tests/other/webauthn/src/main/java/org/keycloak/testsuite/webauthn/pages/WebAuthnPolicyPage.java +++ b/testsuite/integration-arquillian/tests/other/webauthn/src/main/java/org/keycloak/testsuite/webauthn/pages/WebAuthnPolicyPage.java @@ -25,6 +25,7 @@ import org.jboss.arquillian.graphene.page.Page; import org.keycloak.testsuite.console.page.authentication.Authentication; import org.keycloak.testsuite.console.page.fragment.OnOffSwitch; import org.keycloak.testsuite.console.page.idp.mappers.MultivaluedStringProperty; +import org.keycloak.testsuite.page.AbstractPatternFlyAlert; import org.keycloak.testsuite.webauthn.utils.PropertyRequirement; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebElement; @@ -36,6 +37,7 @@ import java.util.function.Supplier; import static org.keycloak.testsuite.util.UIUtils.getTextInputValue; import static org.keycloak.testsuite.util.UIUtils.setTextInputValue; +import static org.keycloak.testsuite.util.WaitUtils.waitForPageToLoad; import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement; /** @@ -98,7 +100,7 @@ public class WebAuthnPolicyPage extends Authentication { } public void setRpEntityName(String entityName) { - waitUntilElement(checkElement(() -> rpEntityName)).is().present(); + waitUntilElement(checkElement(() -> rpEntityName)).is().clickable(); setTextInputValue(rpEntityName, entityName); } @@ -118,7 +120,7 @@ public class WebAuthnPolicyPage extends Authentication { } public void setRpEntityId(String id) { - waitUntilElement(checkElement(() -> rpEntityId)).is().present(); + waitUntilElement(checkElement(() -> rpEntityId)).is().clickable(); setTextInputValue(rpEntityId, id); } @@ -201,7 +203,7 @@ public class WebAuthnPolicyPage extends Authentication { } public void setTimeout(Integer time) { - waitUntilElement(checkElement(() -> timeout)).is().present(); + waitUntilElement(checkElement(() -> timeout)).is().clickable(); setTextInputValue(timeout, time == null ? "0" : String.valueOf(time)); } @@ -224,11 +226,13 @@ public class WebAuthnPolicyPage extends Authentication { public void clickSaveButton() { waitUntilElement(checkElement(() -> saveButton)).is().clickable(); saveButton.click(); + waitForPageToLoad(); } public void clickCancelButton() { waitUntilElement(checkElement(() -> cancelButton)).is().clickable(); cancelButton.click(); + waitForPageToLoad(); } public boolean isSaveButtonEnabled() { diff --git a/testsuite/integration-arquillian/tests/other/webauthn/src/test/java/org/keycloak/testsuite/webauthn/admin/AbstractWebAuthnPolicySettingsTest.java b/testsuite/integration-arquillian/tests/other/webauthn/src/test/java/org/keycloak/testsuite/webauthn/admin/AbstractWebAuthnPolicySettingsTest.java index f5f45fe90e..a1176a5b5a 100644 --- a/testsuite/integration-arquillian/tests/other/webauthn/src/test/java/org/keycloak/testsuite/webauthn/admin/AbstractWebAuthnPolicySettingsTest.java +++ b/testsuite/integration-arquillian/tests/other/webauthn/src/test/java/org/keycloak/testsuite/webauthn/admin/AbstractWebAuthnPolicySettingsTest.java @@ -27,7 +27,9 @@ import org.keycloak.models.Constants; import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.testsuite.AssertEvents; import org.keycloak.testsuite.console.AbstractConsoleTest; +import org.keycloak.testsuite.page.AbstractPatternFlyAlert; import org.keycloak.testsuite.util.UIUtils; +import org.keycloak.testsuite.util.WaitUtils; import org.keycloak.testsuite.webauthn.pages.WebAuthnPolicyPage; import org.keycloak.testsuite.webauthn.updaters.AbstractWebAuthnRealmUpdater; import org.keycloak.testsuite.webauthn.utils.PropertyRequirement; @@ -65,6 +67,7 @@ public abstract class AbstractWebAuthnPolicySettingsTest extends AbstractConsole @Before public void navigateToPolicy() { + driver.manage().window().maximize(); getPolicyPage().navigateTo(); waitForPageToLoad(); getPolicyPage().assertCurrent(); @@ -110,6 +113,7 @@ public abstract class AbstractWebAuthnPolicySettingsTest extends AbstractConsole getPolicyPage().setRpEntityName("newEntityName"); getPolicyPage().clickSaveButton(); + AbstractPatternFlyAlert.waitUntilHidden(); rpEntityName = getPolicyPage().getRpEntityName(); assertThat(rpEntityName, notNullValue()); @@ -117,6 +121,7 @@ public abstract class AbstractWebAuthnPolicySettingsTest extends AbstractConsole getPolicyPage().setRpEntityName(""); getPolicyPage().clickSaveButton(); + AbstractPatternFlyAlert.waitUntilHidden(); rpEntityName = getPolicyPage().getRpEntityName(); assertThat(rpEntityName, notNullValue()); @@ -128,6 +133,7 @@ public abstract class AbstractWebAuthnPolicySettingsTest extends AbstractConsole getPolicyPage().setRpEntityId("rpId123"); getPolicyPage().clickSaveButton(); + AbstractPatternFlyAlert.waitUntilHidden(); rpEntityId = getPolicyPage().getRpEntityId(); assertThat(rpEntityId, notNullValue());