Skip to content

Commit

Permalink
Updated account console treatment
Browse files Browse the repository at this point in the history
Fixes: #528

Signed-off-by: Hynek Mlnarik <[email protected]>
  • Loading branch information
hmlnarik committed Jan 25, 2024
1 parent 776c469 commit eeeeeeb
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* JBoss, Home of Professional Open Source
* Copyright 2017, Red Hat, Inc. and/or its affiliates, and individual
Expand Down Expand Up @@ -53,10 +54,13 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.time.Duration;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.support.ui.FluentWait;
import static java.lang.String.format;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
Expand All @@ -69,6 +73,8 @@
import static org.keycloak.test.TestsHelper.deleteRealm;
import static org.keycloak.test.TestsHelper.importTestRealm;
import static org.keycloak.test.TestsHelper.keycloakBaseUrl;
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
import static org.openqa.selenium.support.ui.ExpectedConditions.urlToBe;

@RunWith(Arquillian.class)
public class ArquillianActionTokenWithAuthenticatorTest {
Expand Down Expand Up @@ -155,7 +161,26 @@ public void setup() {
webDriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

navigateTo("/realms/" + REALM_QUICKSTART_ACTION_TOKEN + "/account/#/personal-info");
navigateTo("/realms/" + REALM_QUICKSTART_ACTION_TOKEN + "/account/#/");
waitForPageToLoad();
}

public void waitForPageToLoad() {
// Taken from org.keycloak.testsuite.util.WaitUtils

String currentUrl = null;

// Ensure the URL is "stable", i.e. is not changing anymore; if it'd changing, some redirects are probably still in progress
for (int maxRedirects = 4; maxRedirects > 0; maxRedirects--) {
currentUrl = webDriver.getCurrentUrl();
FluentWait<WebDriver> wait = new FluentWait<>(webDriver).withTimeout(Duration.ofMillis(250));
try {
wait.until(not(urlToBe(currentUrl)));
}
catch (TimeoutException e) {
break; // URL has not changed recently - ok, the URL is stable and page is current
}
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.support.ui.FluentWait;
import static java.lang.String.format;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
Expand All @@ -66,6 +69,8 @@
import static org.keycloak.test.TestsHelper.deleteRealm;
import static org.keycloak.test.TestsHelper.importTestRealm;
import static org.keycloak.test.TestsHelper.keycloakBaseUrl;
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
import static org.openqa.selenium.support.ui.ExpectedConditions.urlToBe;

@RunWith(Arquillian.class)
public class ArquillianActionTokenTest {
Expand Down Expand Up @@ -141,7 +146,26 @@ public void setup() {
webDriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

navigateTo("/realms/" + REALM_QUICKSTART_ACTION_TOKEN + "/account/#/personal-info");
navigateTo("/realms/" + REALM_QUICKSTART_ACTION_TOKEN + "/account/#/");
waitForPageToLoad();
}

public void waitForPageToLoad() {
// Taken from org.keycloak.testsuite.util.WaitUtils

String currentUrl = null;

// Ensure the URL is "stable", i.e. is not changing anymore; if it'd changing, some redirects are probably still in progress
for (int maxRedirects = 4; maxRedirects > 0; maxRedirects--) {
currentUrl = webDriver.getCurrentUrl();
FluentWait<WebDriver> wait = new FluentWait<>(webDriver).withTimeout(Duration.ofMillis(250));
try {
wait.until(not(urlToBe(currentUrl)));
}
catch (TimeoutException e) {
break; // URL has not changed recently - ok, the URL is stable and page is current
}
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@
import org.keycloak.test.FluentTestsHelper;
import org.keycloak.test.page.LoginPage;
import org.keycloak.quickstart.storage.user.MyExampleUserStorageProviderFactory;
import java.time.Duration;
import org.openqa.selenium.WebDriver;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.support.ui.FluentWait;
import static java.lang.String.format;
import static org.junit.Assert.assertEquals;
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
import static org.openqa.selenium.support.ui.ExpectedConditions.urlToBe;

@RunWith(Arquillian.class)
public class ArquillianJpaStorageTest {
Expand Down Expand Up @@ -117,7 +122,26 @@ private String addProvider() {
}

private void navigateToAccount(String user, String password) {
navigateTo(format("/realms/%s/account/#/personal-info", testsHelper.getTestRealmName()));
navigateTo(format("/realms/%s/account/#/", testsHelper.getTestRealmName()));
waitForPageToLoad();
loginPage.login(user, password);
}

public void waitForPageToLoad() {
// Taken from org.keycloak.testsuite.util.WaitUtils

String currentUrl = null;

// Ensure the URL is "stable", i.e. is not changing anymore; if it'd changing, some redirects are probably still in progress
for (int maxRedirects = 4; maxRedirects > 0; maxRedirects--) {
currentUrl = webDriver.getCurrentUrl();
FluentWait<WebDriver> wait = new FluentWait<>(webDriver).withTimeout(Duration.ofMillis(250));
try {
wait.until(not(urlToBe(currentUrl)));
}
catch (TimeoutException e) {
break; // URL has not changed recently - ok, the URL is stable and page is current
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.keycloak.credential.CredentialInput;
import org.keycloak.credential.CredentialInputUpdater;
import org.keycloak.credential.CredentialInputValidator;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.credential.UserCredentialManager;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.SubjectCredentialManager;
Expand Down Expand Up @@ -85,7 +85,7 @@ public String getUsername() {

@Override
public SubjectCredentialManager credentialManager() {
return new LegacyUserCredentialManager(session, realm, this);
return new UserCredentialManager(session, realm, this);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@
import org.openqa.selenium.WebDriver;

import java.io.IOException;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.support.ui.FluentWait;
import static java.lang.String.format;
import static org.junit.Assert.assertEquals;
import static org.keycloak.quickstart.util.StorageManager.addUser;
import static org.keycloak.quickstart.util.StorageManager.createStorage;
import static org.keycloak.quickstart.util.StorageManager.deleteStorage;
import static org.keycloak.quickstart.util.StorageManager.getPropertyFile;
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
import static org.openqa.selenium.support.ui.ExpectedConditions.urlToBe;


@RunWith(Arquillian.class)
Expand Down Expand Up @@ -153,7 +158,26 @@ private void addProvider(String providerId) {
}

private void navigateToAccount(String user, String password) {
navigateTo(format("/realms/%s/account/#/personal-info", testsHelper.getTestRealmName()));
navigateTo(format("/realms/%s/account/#/", testsHelper.getTestRealmName()));
waitForPageToLoad();
loginPage.login(user, password);
}

public void waitForPageToLoad() {
// Taken from org.keycloak.testsuite.util.WaitUtils

String currentUrl = null;

// Ensure the URL is "stable", i.e. is not changing anymore; if it'd changing, some redirects are probably still in progress
for (int maxRedirects = 4; maxRedirects > 0; maxRedirects--) {
currentUrl = webDriver.getCurrentUrl();
FluentWait<WebDriver> wait = new FluentWait<>(webDriver).withTimeout(Duration.ofMillis(250));
try {
wait.until(not(urlToBe(currentUrl)));
}
catch (TimeoutException e) {
break; // URL has not changed recently - ok, the URL is stable and page is current
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@
*/
public class ConsolePage {

@FindBy(id = "user-name")
private WebElement username;

@FindBy(id = "signOutButton")
@FindBy(xpath = "//a[text() = 'Sign out']")
private WebElement logoutLink;

@FindBy(xpath = "//div[@data-testid='options']")
private WebElement profileMenu;

public void logout() {
profileMenu.click();
logoutLink.click();
}

public String getUser() {
waitAjax().until().element(username).value().not().equalTo("");
return username.getAttribute("value");
waitAjax().until().element(profileMenu).text().not().equalTo("");
return profileMenu.getText();
}

}

0 comments on commit eeeeeeb

Please sign in to comment.