From 46ebff21635b0cc4dcc62dc451a27b5fd5d48322 Mon Sep 17 00:00:00 2001 From: vmuzikar Date: Mon, 29 Jan 2018 11:13:49 +0100 Subject: [PATCH] KEYCLOAK-6331 Fix and stabilize Console UI tests --- .../org/keycloak/testsuite/util/UIUtils.java | 21 ++++++++++++++++++ .../SAMLClientCredentialsForm.java | 22 +++++++++---------- .../console/page/realm/TokenSettings.java | 15 ++++--------- .../testsuite/console/page/users/Users.java | 2 +- .../testsuite/console/realm/TokensTest.java | 3 --- 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/UIUtils.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/UIUtils.java index 84cd7c8bfb..9c9ad527dd 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/UIUtils.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/UIUtils.java @@ -1,5 +1,6 @@ package org.keycloak.testsuite.util; +import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; @@ -59,4 +60,24 @@ public final class UIUtils { public static void navigateToLink(WebElement element) { URLUtils.navigateToUri(element.getAttribute("href"), true); } + + /** + * This is meant mainly for file uploads in Admin Console where the input fields are hidden + * + * @param element + * @param keys + */ + public static void sendKeysToInvisibleElement(WebElement element, CharSequence... keys) { + if (element.isDisplayed()) { + element.sendKeys(keys); + return; + } + + JavascriptExecutor jsExecutor = (JavascriptExecutor) getCurrentDriver(); + String styleBckp = element.getAttribute("style"); + + jsExecutor.executeScript("arguments[0].setAttribute('style', 'display:block !important');", element); + element.sendKeys(keys); + jsExecutor.executeScript("arguments[0].setAttribute('style', '" + styleBckp + "');", element); + } } diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/credentials/SAMLClientCredentialsForm.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/credentials/SAMLClientCredentialsForm.java index 1790834707..b95cbb07d2 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/credentials/SAMLClientCredentialsForm.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/credentials/SAMLClientCredentialsForm.java @@ -11,13 +11,15 @@ import java.net.URL; import static org.keycloak.services.resources.admin.ClientAttributeCertificateResource.CERTIFICATE_PEM; import static org.keycloak.common.util.KeystoreUtil.KeystoreFormat.JKS; import static org.keycloak.common.util.KeystoreUtil.KeystoreFormat.PKCS12; +import static org.keycloak.testsuite.util.UIUtils.clickLink; +import static org.keycloak.testsuite.util.UIUtils.sendKeysToInvisibleElement; /** * @author Bruno Oliveira */ public class SAMLClientCredentialsForm extends Form { - private static final String PATH_PREFIX = "saml-keys" + File.separator; + private static final String PATH_PREFIX = "saml-keys/"; @FindBy(linkText = "SAML Keys") private WebElement samlKeysLink; @@ -68,21 +70,19 @@ public class SAMLClientCredentialsForm extends Form { } private void uploadFile(String file) { - URL fileUrl = (getClass().getClassLoader().getResource(file)); - selectFileButton.sendKeys(fileUrl.getFile()); - uploadButton.click(); + URL fileUrl = getClass().getClassLoader().getResource(file); + String absolutePath = new File(fileUrl.getFile()).getAbsolutePath(); // For Windows, we need to use File.getAbsolutePath() + sendKeysToInvisibleElement(selectFileButton, absolutePath); + clickLink(uploadButton); } private void fillCredentials() { - uploadKeyAlias.clear(); - uploadKeyAlias.sendKeys("samlKey"); - - uploadStorePassword.clear(); - uploadStorePassword.sendKeys("secret"); + setInputValue(uploadKeyAlias, "samlKey"); + setInputValue(uploadStorePassword, "secret"); } private void navigateToImport() { - samlKeysLink.click(); - importButton.click(); + clickLink(samlKeysLink); + clickLink(importButton); } } diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/TokenSettings.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/TokenSettings.java index ff131becbf..77381cd062 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/TokenSettings.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/TokenSettings.java @@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit; import static java.lang.String.valueOf; import static org.apache.commons.lang3.text.WordUtils.capitalize; -import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement; +import static org.keycloak.testsuite.util.WaitUtils.pause; /** * @@ -82,38 +82,31 @@ public class TokenSettings extends RealmSettings { } public void setOperation(String tokenType, int time, TimeUnit unit) { - waitUntilElement(sessionTimeout).is().present(); - actionTokenAttributeSelect.selectByValue(tokenType.toLowerCase()); + selectOperation(tokenType); setTimeout(actionTokenAttributeUnit, actionTokenAttributeTime, time, unit); } private void setTimeout(Select timeoutElement, WebElement unitElement, int timeout, TimeUnit unit) { - waitUntilElement(sessionTimeout).is().present(); timeoutElement.selectByValue(capitalize(unit.name().toLowerCase())); - unitElement.clear(); - unitElement.sendKeys(valueOf(timeout)); + setInputValue(unitElement, valueOf(timeout)); } public boolean isOperationEquals(String tokenType, int timeout, TimeUnit unit) { selectOperation(tokenType); - waitUntilElement(sessionTimeout).is().present(); - actionTokenAttributeSelect.selectByValue(tokenType.toLowerCase()); - return actionTokenAttributeTime.getAttribute("value").equals(Integer.toString(timeout)) && actionTokenAttributeUnit.getFirstSelectedOption().getText().equals(capitalize(unit.name().toLowerCase())); } public void resetActionToken(String tokenType) { selectOperation(tokenType); - waitUntilElement(resetButton).is().visible(); resetButton.click(); } public void selectOperation(String tokenType) { - waitUntilElement(sessionTimeout).is().present(); actionTokenAttributeSelect.selectByValue(tokenType.toLowerCase()); + pause(500); // wait for the form to be updated; there isn't currently a better way } } } diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/users/Users.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/users/Users.java index fea10a90fa..7d541b1255 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/users/Users.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/users/Users.java @@ -78,7 +78,7 @@ public class Users extends AdminConsoleRealm { } public void clickUser(String username) { - clickLink(getRowByUsername(username).findElement(By.xpath("./td[position()=1]/a"))); + clickLink(getRowByUsername(username).findElement(By.xpath("./td[position()=1]"))); } public void editUser(String username) { diff --git a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/TokensTest.java b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/TokensTest.java index 9307a62490..25da05a134 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/TokensTest.java +++ b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/TokensTest.java @@ -106,7 +106,6 @@ public class TokensTest extends AbstractRealmTest { assertAlertSuccess(); loginToTestRealmConsoleAs(testUser); - driver.navigate().refresh(); tokenSettingsPage.navigateTo(); tokenSettingsPage.form().selectOperation(VerifyEmailActionToken.TOKEN_TYPE); @@ -124,7 +123,6 @@ public class TokensTest extends AbstractRealmTest { assertAlertSuccess(); loginToTestRealmConsoleAs(testUser); - driver.navigate().refresh(); tokenSettingsPage.navigateTo(); assertTrue("User action token for verify e-mail expected", @@ -150,7 +148,6 @@ public class TokensTest extends AbstractRealmTest { assertAlertSuccess(); loginToTestRealmConsoleAs(testUser); - driver.navigate().refresh(); tokenSettingsPage.navigateTo(); assertTrue("User action token for verify e-mail expected",