KEYCLOAK-6331 Fix and stabilize Console UI tests
This commit is contained in:
parent
afa26f7d3c
commit
46ebff2163
5 changed files with 37 additions and 26 deletions
|
@ -1,5 +1,6 @@
|
||||||
package org.keycloak.testsuite.util;
|
package org.keycloak.testsuite.util;
|
||||||
|
|
||||||
|
import org.openqa.selenium.JavascriptExecutor;
|
||||||
import org.openqa.selenium.TimeoutException;
|
import org.openqa.selenium.TimeoutException;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
|
@ -59,4 +60,24 @@ public final class UIUtils {
|
||||||
public static void navigateToLink(WebElement element) {
|
public static void navigateToLink(WebElement element) {
|
||||||
URLUtils.navigateToUri(element.getAttribute("href"), true);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,15 @@ import java.net.URL;
|
||||||
import static org.keycloak.services.resources.admin.ClientAttributeCertificateResource.CERTIFICATE_PEM;
|
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.JKS;
|
||||||
import static org.keycloak.common.util.KeystoreUtil.KeystoreFormat.PKCS12;
|
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 <a href="mailto:bruno@abstractj.org">Bruno Oliveira</a>
|
* @author <a href="mailto:bruno@abstractj.org">Bruno Oliveira</a>
|
||||||
*/
|
*/
|
||||||
public class SAMLClientCredentialsForm extends Form {
|
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")
|
@FindBy(linkText = "SAML Keys")
|
||||||
private WebElement samlKeysLink;
|
private WebElement samlKeysLink;
|
||||||
|
@ -68,21 +70,19 @@ public class SAMLClientCredentialsForm extends Form {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uploadFile(String file) {
|
private void uploadFile(String file) {
|
||||||
URL fileUrl = (getClass().getClassLoader().getResource(file));
|
URL fileUrl = getClass().getClassLoader().getResource(file);
|
||||||
selectFileButton.sendKeys(fileUrl.getFile());
|
String absolutePath = new File(fileUrl.getFile()).getAbsolutePath(); // For Windows, we need to use File.getAbsolutePath()
|
||||||
uploadButton.click();
|
sendKeysToInvisibleElement(selectFileButton, absolutePath);
|
||||||
|
clickLink(uploadButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillCredentials() {
|
private void fillCredentials() {
|
||||||
uploadKeyAlias.clear();
|
setInputValue(uploadKeyAlias, "samlKey");
|
||||||
uploadKeyAlias.sendKeys("samlKey");
|
setInputValue(uploadStorePassword, "secret");
|
||||||
|
|
||||||
uploadStorePassword.clear();
|
|
||||||
uploadStorePassword.sendKeys("secret");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void navigateToImport() {
|
private void navigateToImport() {
|
||||||
samlKeysLink.click();
|
clickLink(samlKeysLink);
|
||||||
importButton.click();
|
clickLink(importButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static java.lang.String.valueOf;
|
import static java.lang.String.valueOf;
|
||||||
import static org.apache.commons.lang3.text.WordUtils.capitalize;
|
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) {
|
public void setOperation(String tokenType, int time, TimeUnit unit) {
|
||||||
waitUntilElement(sessionTimeout).is().present();
|
selectOperation(tokenType);
|
||||||
actionTokenAttributeSelect.selectByValue(tokenType.toLowerCase());
|
|
||||||
setTimeout(actionTokenAttributeUnit, actionTokenAttributeTime, time, unit);
|
setTimeout(actionTokenAttributeUnit, actionTokenAttributeTime, time, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTimeout(Select timeoutElement, WebElement unitElement,
|
private void setTimeout(Select timeoutElement, WebElement unitElement,
|
||||||
int timeout, TimeUnit unit) {
|
int timeout, TimeUnit unit) {
|
||||||
waitUntilElement(sessionTimeout).is().present();
|
|
||||||
timeoutElement.selectByValue(capitalize(unit.name().toLowerCase()));
|
timeoutElement.selectByValue(capitalize(unit.name().toLowerCase()));
|
||||||
unitElement.clear();
|
setInputValue(unitElement, valueOf(timeout));
|
||||||
unitElement.sendKeys(valueOf(timeout));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOperationEquals(String tokenType, int timeout, TimeUnit unit) {
|
public boolean isOperationEquals(String tokenType, int timeout, TimeUnit unit) {
|
||||||
selectOperation(tokenType);
|
selectOperation(tokenType);
|
||||||
|
|
||||||
waitUntilElement(sessionTimeout).is().present();
|
|
||||||
actionTokenAttributeSelect.selectByValue(tokenType.toLowerCase());
|
|
||||||
|
|
||||||
return actionTokenAttributeTime.getAttribute("value").equals(Integer.toString(timeout)) &&
|
return actionTokenAttributeTime.getAttribute("value").equals(Integer.toString(timeout)) &&
|
||||||
actionTokenAttributeUnit.getFirstSelectedOption().getText().equals(capitalize(unit.name().toLowerCase()));
|
actionTokenAttributeUnit.getFirstSelectedOption().getText().equals(capitalize(unit.name().toLowerCase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetActionToken(String tokenType) {
|
public void resetActionToken(String tokenType) {
|
||||||
selectOperation(tokenType);
|
selectOperation(tokenType);
|
||||||
waitUntilElement(resetButton).is().visible();
|
|
||||||
resetButton.click();
|
resetButton.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectOperation(String tokenType) {
|
public void selectOperation(String tokenType) {
|
||||||
waitUntilElement(sessionTimeout).is().present();
|
|
||||||
actionTokenAttributeSelect.selectByValue(tokenType.toLowerCase());
|
actionTokenAttributeSelect.selectByValue(tokenType.toLowerCase());
|
||||||
|
pause(500); // wait for the form to be updated; there isn't currently a better way
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class Users extends AdminConsoleRealm {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clickUser(String username) {
|
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) {
|
public void editUser(String username) {
|
||||||
|
|
|
@ -106,7 +106,6 @@ public class TokensTest extends AbstractRealmTest {
|
||||||
assertAlertSuccess();
|
assertAlertSuccess();
|
||||||
|
|
||||||
loginToTestRealmConsoleAs(testUser);
|
loginToTestRealmConsoleAs(testUser);
|
||||||
driver.navigate().refresh();
|
|
||||||
|
|
||||||
tokenSettingsPage.navigateTo();
|
tokenSettingsPage.navigateTo();
|
||||||
tokenSettingsPage.form().selectOperation(VerifyEmailActionToken.TOKEN_TYPE);
|
tokenSettingsPage.form().selectOperation(VerifyEmailActionToken.TOKEN_TYPE);
|
||||||
|
@ -124,7 +123,6 @@ public class TokensTest extends AbstractRealmTest {
|
||||||
assertAlertSuccess();
|
assertAlertSuccess();
|
||||||
|
|
||||||
loginToTestRealmConsoleAs(testUser);
|
loginToTestRealmConsoleAs(testUser);
|
||||||
driver.navigate().refresh();
|
|
||||||
|
|
||||||
tokenSettingsPage.navigateTo();
|
tokenSettingsPage.navigateTo();
|
||||||
assertTrue("User action token for verify e-mail expected",
|
assertTrue("User action token for verify e-mail expected",
|
||||||
|
@ -150,7 +148,6 @@ public class TokensTest extends AbstractRealmTest {
|
||||||
assertAlertSuccess();
|
assertAlertSuccess();
|
||||||
|
|
||||||
loginToTestRealmConsoleAs(testUser);
|
loginToTestRealmConsoleAs(testUser);
|
||||||
driver.navigate().refresh();
|
|
||||||
|
|
||||||
tokenSettingsPage.navigateTo();
|
tokenSettingsPage.navigateTo();
|
||||||
assertTrue("User action token for verify e-mail expected",
|
assertTrue("User action token for verify e-mail expected",
|
||||||
|
|
Loading…
Reference in a new issue