KEYCLOAK-6331 Fix and stabilize Console UI tests

This commit is contained in:
vmuzikar 2018-01-29 11:13:49 +01:00 committed by Pavel Drozd
parent afa26f7d3c
commit 46ebff2163
5 changed files with 37 additions and 26 deletions

View file

@ -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);
}
}

View file

@ -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 <a href="mailto:bruno@abstractj.org">Bruno Oliveira</a>
*/
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);
}
}

View file

@ -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
}
}
}

View file

@ -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) {

View file

@ -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",