KEYCLOAK-12635 KEYCLOAK-12935 KEYCLOAK-13023 UI test fixes

This commit is contained in:
vmuzikar 2020-02-06 11:29:58 +01:00 committed by Bruno Oliveira da Silva
parent eaaff6e555
commit de8ba75399
19 changed files with 76 additions and 40 deletions

View file

@ -19,6 +19,7 @@ package org.keycloak.testsuite.page;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.logging.Logger;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -46,6 +47,12 @@ public class Form {
public void save() {
clickLink(save);
try {
AbstractPatternFlyAlert.waitUntilDisplayed();
}
catch (TimeoutException e) {
log.warn("Timeout waiting for alert to be displayed");
}
}
public void cancel() {

View file

@ -17,7 +17,9 @@
package org.keycloak.testsuite.page;
import org.keycloak.testsuite.util.WaitUtils;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.FindBy;
import static org.junit.Assert.assertEquals;
@ -85,10 +87,20 @@ public class PatternFlyClosableAlert extends AbstractPatternFlyAlert {
}
public void close() {
closeButton.click();
WaitUtils.pause(500); // Sometimes, when a test is too fast,
// one of the consecutive alerts is not displayed;
// to prevent this we need to slow down a bit
try {
closeButton.click();
WaitUtils.pause(500); // Sometimes, when a test is too fast,
// one of the consecutive alerts is not displayed;
// to prevent this we need to slow down a bit
}
catch (WebDriverException e) {
if (driver instanceof InternetExplorerDriver) {
log.warn("Failed to close the alert; test is probably too slow and alert has already closed itself");
}
else {
throw e;
}
}
}
}

View file

@ -68,12 +68,7 @@ public final class UIUtils {
public static void clickLink(WebElement element) {
WebDriver driver = getCurrentDriver();
// Sometimes at some weird specific conditions, Firefox fail to click an element
// because the element is at the edge of the view and need to be scrolled on "manually" (normally the driver
// should do this automatically)
if (driver instanceof FirefoxDriver) {
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
}
waitUntilElement(element).is().clickable();
if (driver instanceof SafariDriver && !element.isDisplayed()) { // Safari sometimes thinks an element is not visible
// even though it is. In this case we just move the cursor and click.

View file

@ -51,7 +51,7 @@ public final class WaitUtils {
public static final Integer PAGELOAD_TIMEOUT_MILLIS = Integer.parseInt(System.getProperty(PAGELOAD_TIMEOUT_PROP, "10000"));
public static final int IMPLICIT_ELEMENT_WAIT_MILLIS = 750;
public static final int IMPLICIT_ELEMENT_WAIT_MILLIS = 1500; // high value means more stable but slower tests; it needs to be balanced
// Should be no longer necessary for finding elements since we have implicit wait
public static ElementBuilder<Void> waitUntilElement(By by) {
@ -140,7 +140,7 @@ public final class WaitUtils {
else if (
currentUrl.matches("^[^\\/]+:\\/\\/[^\\/]+\\/auth\\/realms\\/[^\\/]+\\/account\\/.*#/.+$") // check for new Account Console URL
) {
pause(1000); // TODO rework this temporary workaround once KEYCLOAK-11201 and/or KEYCLOAK-8181 are fixed
pause(2000); // TODO rework this temporary workaround once KEYCLOAK-11201 and/or KEYCLOAK-8181 are fixed
}
if (waitCondition != null) {

View file

@ -40,6 +40,8 @@ import java.util.Locale;
import java.util.Map;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.is;
@ -196,7 +198,9 @@ public class DeviceActivityTest extends BaseAccountPageTest {
public void timesTests() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE, MMMM d, yyyy h:mm a", Locale.ENGLISH);
LocalDateTime now = LocalDateTime.now();
LocalDateTime nowPlus1 = now.plusMinutes(1);
String nowStr = now.format(formatter);
String nowStrPlus1 = nowPlus1.format(formatter);
String sessionId = createSession(Browsers.CHROME);
@ -219,7 +223,7 @@ public class DeviceActivityTest extends BaseAccountPageTest {
assertTrue("Last access should be after started at", lastAccessed.isAfter(startedAt));
assertTrue("Expires at should be after last access", expiresAt.isAfter(lastAccessed));
assertTrue("Last accessed should be in the future", lastAccessed.isAfter(now));
assertEquals(nowStr, startedAtStr);
assertThat(startedAtStr, either(equalTo(nowStr)).or(equalTo(nowStrPlus1)));
int ssoLifespan = testRealmResource().toRepresentation().getSsoSessionMaxLifespan();
assertEquals(startedAt.plusSeconds(ssoLifespan), expiresAt);

View file

@ -19,6 +19,7 @@ package org.keycloak.testsuite.ui.account2;
import org.jboss.arquillian.graphene.page.Page;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.keycloak.models.UserModel;
import org.keycloak.representations.idm.RealmRepresentation;
@ -35,6 +36,7 @@ import static org.junit.Assert.assertEquals;
/**
* @author Vaclav Muzikar <vmuzikar@redhat.com>
*/
@Ignore // TODO remove this once KEYCLOAK-12936 is resolved
public class InternationalizationTest extends AbstractAccountTest {
@Page
private WelcomeScreen welcomeScreen;

View file

@ -18,6 +18,7 @@
package org.keycloak.testsuite.ui.account2;
import org.jboss.arquillian.graphene.page.Page;
import org.junit.Ignore;
import org.junit.Test;
import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.RealmRepresentation;
@ -126,6 +127,7 @@ public class ReferrerTest extends AbstractAccountTest {
* Test that i18n and referrer work well together
*/
@Test
@Ignore // TODO remove this once KEYCLOAK-12936 is resolved
public void i18nTest() {
RealmRepresentation realm = testRealmResource().toRepresentation();
configureInternationalizationForRealm(realm);

View file

@ -353,10 +353,10 @@ public class SigningInTest extends BaseAccountPageTest {
assertTrue(userCredential.isPresent());
assertEquals(countBeforeRemove, userCredential.getCredentialType().getUserCredentialsCount());
});
signingInPage.alert().assertSuccess();
assertFalse(userCredential.isPresent());
assertEquals(countBeforeRemove - 1, userCredential.getCredentialType().getUserCredentialsCount());
signingInPage.alert().assertSuccess();
}
private void assertUserCredential(String expectedUserLabel, boolean removable, SigningInPage.UserCredential userCredential) {

View file

@ -25,6 +25,8 @@ import org.openqa.selenium.support.FindBy;
import java.util.ArrayList;
import java.util.List;
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
/**
* @author Vaclav Muzikar <vmuzikar@redhat.com>
*/
@ -38,8 +40,9 @@ public class ApplicationsPage extends AbstractLoggedInPage {
}
public void toggleApplicationDetails(String clientId) {
WebElement expandButton = driver.findElement(By.xpath("//button[@id='application-toggle-" + clientId + "']"));
expandButton.click();
By selector = By.xpath("//button[@id='application-toggle-" + clientId + "']");
waitUntilElement(selector).is().clickable();
driver.findElement(selector).click();
}
public List<ClientRepresentation> getApplications() {

View file

@ -5,6 +5,8 @@ import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import static org.keycloak.testsuite.util.UIUtils.clickBtnAndWaitForAlert;
/**
* @author tkyjovsk
* @author mhajas
@ -34,7 +36,7 @@ public class RequiredActions extends Authentication {
WebElement checkbox = requiredActionTable.findElement(By.id(id));
if (checkbox.isEnabled() && checkbox.isSelected() != value) {
checkbox.click();
clickBtnAndWaitForAlert(checkbox);
}
}

View file

@ -8,6 +8,7 @@ import org.openqa.selenium.support.ui.Select;
import java.util.List;
import java.util.stream.Collectors;
import static org.keycloak.testsuite.util.UIUtils.clickLink;
import static org.keycloak.testsuite.util.UIUtils.getTextFromElement;
import static org.keycloak.testsuite.util.UIUtils.performOperationWithPageReload;
@ -80,22 +81,22 @@ public class Flows extends Authentication {
}
public void clickNew() {
newButton.click();
clickLink(newButton);
}
public void clickCopy() {
copyButton.click();
clickLink(copyButton);
}
public void clickDelete() {
deleteButton.click();
clickLink(deleteButton);
}
public void clickAddExecution() {
addExecutionButton.click();
clickLink(addExecutionButton);
}
public void clickAddFlow() {
addFlowButton.click();
clickLink(addFlowButton);
}
}

View file

@ -2,11 +2,13 @@ package org.keycloak.testsuite.console.page.clients;
import org.jboss.arquillian.graphene.fragment.Root;
import org.keycloak.testsuite.console.page.fragment.Breadcrumb;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import static org.keycloak.testsuite.console.page.fragment.Breadcrumb.BREADCRUMB_XPATH;
import static org.keycloak.testsuite.util.UIUtils.clickLink;
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
import org.openqa.selenium.NoSuchElementException;
@ -17,6 +19,7 @@ import org.openqa.selenium.NoSuchElementException;
public class Client extends Clients {
public static final String ID = "id"; // TODO client.id vs client.clientId
public static final String CLIENT_TABS_XPATH = "//div[@data-ng-controller='ClientTabCtrl']/ul";
@Override
public String getUriFragment() {
@ -50,10 +53,11 @@ public class Client extends Clients {
modalDialog.confirmDeletion();
}
@FindBy(xpath = "//div[@data-ng-controller='ClientTabCtrl']/ul")
@FindBy(xpath = CLIENT_TABS_XPATH)
protected ClientTabs clientTabs;
public ClientTabs tabs() {
waitUntilElement(By.xpath(CLIENT_TABS_XPATH)).is().present(); // a workaround to make FF stable
return clientTabs;
}

View file

@ -10,6 +10,7 @@ import org.openqa.selenium.support.FindBy;
import java.util.ArrayList;
import java.util.List;
import static org.keycloak.testsuite.util.UIUtils.clickLink;
import static org.keycloak.testsuite.util.UIUtils.getTextFromElement;
/**
@ -88,7 +89,7 @@ public class ClientMappers extends Client {
}
public void clickAddSelectedBuiltinMapper() {
addSelectedButton.click();
clickLink(addSelectedButton);
}
public ProtocolMapperRepresentation getMappingFromRow(WebElement row) {

View file

@ -12,7 +12,7 @@ import org.openqa.selenium.support.ui.Select;
import java.util.ArrayList;
import java.util.List;
import static org.keycloak.testsuite.util.UIUtils.clickLink;
import static org.keycloak.testsuite.util.UIUtils.clickBtnAndWaitForAlert;
import static org.keycloak.testsuite.util.UIUtils.getTextFromElement;
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
@ -316,15 +316,15 @@ public class LdapUserProviderForm extends Form {
}
public void testConnection() {
clickLink(testConnectionButton);
clickBtnAndWaitForAlert(testConnectionButton);
}
public void testAuthentication() {
clickLink(testAuthenticationButton);
clickBtnAndWaitForAlert(testAuthenticationButton);
}
public void synchronizeAllUsers() {
waitUntilElement(synchronizeAllUsersButton).is().present();
clickLink(synchronizeAllUsersButton);
clickBtnAndWaitForAlert(synchronizeAllUsersButton);
}
}

View file

@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.keycloak.common.Profile.Feature.UPLOAD_SCRIPTS;
import static org.keycloak.testsuite.util.UIUtils.refreshPageAndWaitForLoad;
import java.util.UUID;
@ -185,7 +186,7 @@ public class AggregatePolicyManagementTest extends AbstractAuthorizationSettings
@Test
public void testCreateWithChildAndSelectedPolicy() {
authorizationPage.getDriver().navigate().refresh();
refreshPageAndWaitForLoad();
AggregatePolicyRepresentation expected = new AggregatePolicyRepresentation();
expected.setName("Test Child Create And Select Aggregate Policy");

View file

@ -27,6 +27,7 @@ import org.keycloak.testsuite.console.page.idp.IdentityProviders;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.keycloak.testsuite.util.UIUtils.refreshPageAndWaitForLoad;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals;
/**
@ -65,7 +66,7 @@ public class IdentityProviderTest extends AbstractConsoleTest {
assertPasswordIsUnmasked();
createIdentityProviderPage.form().save();
assertAlertSuccess();
driver.navigate().refresh();
refreshPageAndWaitForLoad();
assertCurrentUrlEquals(identityProviderPage);
assertEyeButtonIsDisabled();
@ -78,7 +79,7 @@ public class IdentityProviderTest extends AbstractConsoleTest {
assertPasswordIsUnmasked();
identityProviderPage.form().save();
assertAlertSuccess();
driver.navigate().refresh();
refreshPageAndWaitForLoad();
assertCurrentUrlEquals(identityProviderPage);
assertEyeButtonIsDisabled();

View file

@ -67,7 +67,7 @@ public class InternationalizationTest extends AbstractRealmTest {
localeDropdown.selectByText(LOCALE_CS_NAME);
assertLocale(".//label[@for='password']", LABEL_CS_PASSWORD);
loginToTestRealmConsoleAs(testUser);
loginPage.form().login(testUser);
assertConsoleLocale(LABEL_CS_REALM_SETTINGS);
testRealmAccountPage.navigateTo();

View file

@ -75,7 +75,7 @@ public class SecurityDefensesTest extends AbstractRealmTest {
@Test
public void maxLoginFailuresTest() throws InterruptedException {
final short secondsToWait = 10; // For slower browsers/webdrivers (like IE) we need higher value
final short secondsToWait = 30; // For slower browsers/webdrivers (like IE) we need higher value
final short maxLoginFailures = 2;
bruteForceDetectionPage.form().setProtectionEnabled(true);
@ -91,11 +91,11 @@ public class SecurityDefensesTest extends AbstractRealmTest {
@Test
public void quickLoginCheck() throws InterruptedException {
final short secondsToWait = 10;
final short secondsToWait = 30;
bruteForceDetectionPage.form().setProtectionEnabled(true);
bruteForceDetectionPage.form().setMaxLoginFailures("100");
bruteForceDetectionPage.form().setQuickLoginCheckInput("10000");
bruteForceDetectionPage.form().setQuickLoginCheckInput("30000"); // IE is very slow
bruteForceDetectionPage.form().setMinQuickLoginWaitSelect(BruteForceDetection.TimeSelectValues.SECONDS);
bruteForceDetectionPage.form().setMinQuickLoginWaitInput(String.valueOf(secondsToWait));
bruteForceDetectionPage.form().save();
@ -106,12 +106,12 @@ public class SecurityDefensesTest extends AbstractRealmTest {
@Test
public void maxWaitLoginFailures() throws InterruptedException {
final short secondsToWait = 15;
final short secondsToWait = 40;
bruteForceDetectionPage.form().setProtectionEnabled(true);
bruteForceDetectionPage.form().setMaxLoginFailures("1");
bruteForceDetectionPage.form().setWaitIncrementSelect(BruteForceDetection.TimeSelectValues.MINUTES);
bruteForceDetectionPage.form().setWaitIncrementInput("10");
bruteForceDetectionPage.form().setWaitIncrementInput("30");
bruteForceDetectionPage.form().setMaxWaitSelect(BruteForceDetection.TimeSelectValues.SECONDS);
bruteForceDetectionPage.form().setMaxWaitInput(String.valueOf(secondsToWait));
bruteForceDetectionPage.form().save();

View file

@ -39,6 +39,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.keycloak.testsuite.util.UIUtils.refreshPageAndWaitForLoad;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWithLoginUrlOf;
@ -76,7 +77,7 @@ public class TokensTest extends AbstractRealmTest {
loginToTestRealmConsoleAs(testUser);
waitForTimeout(TIMEOUT + 2);
driver.navigate().refresh();
refreshPageAndWaitForLoad();
log.debug(driver.getCurrentUrl());
assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
@ -90,11 +91,11 @@ public class TokensTest extends AbstractRealmTest {
loginToTestRealmConsoleAs(testUser);
waitForTimeout(TIMEOUT / 2);
driver.navigate().refresh();
refreshPageAndWaitForLoad();
assertCurrentUrlStartsWith(testRealmAdminConsolePage); // assert still logged in (within lifespan)
waitForTimeout(TIMEOUT / 2 + 2);
driver.navigate().refresh();
refreshPageAndWaitForLoad();
log.debug(driver.getCurrentUrl());
assertCurrentUrlStartsWithLoginUrlOf(testRealmPage); // assert logged out (lifespan exceeded)