mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-25 16:42:34 +00:00
Migrate i18n package to new testsuite
Closes #44520 Signed-off-by: stianst <stianst@gmail.com>
This commit is contained in:
@@ -240,6 +240,11 @@ public class RealmConfigBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public RealmConfigBuilder resetPasswordAllowed(boolean allowed) {
|
||||
rep.setResetPasswordAllowed(allowed);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RealmConfigBuilder clientPolicy(ClientPolicyRepresentation clienPolicyRep) {
|
||||
ClientPoliciesRepresentation clientPolicies = rep.getParsedClientPolicies();
|
||||
if (clientPolicies == null) {
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.testframework.ui.page;
|
||||
|
||||
import org.keycloak.testframework.ui.webdriver.ManagedWebDriver;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.NoSuchElementException;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
public abstract class AbstractLoginPage extends AbstractPage {
|
||||
|
||||
@FindBy(xpath = "//select[@aria-label='languages']/option[@selected]")
|
||||
private WebElement selectedLanguage;
|
||||
|
||||
@FindBy(xpath = "//select[@aria-label='languages']")
|
||||
private WebElement languages;
|
||||
|
||||
@FindBy(id = "kc-current-locale-link")
|
||||
private WebElement languageTextBase; // base theme
|
||||
|
||||
@FindBy(id = "kc-locale-dropdown")
|
||||
private WebElement localeDropdownBase; // base theme
|
||||
|
||||
public AbstractLoginPage(ManagedWebDriver driver) {
|
||||
super(driver);
|
||||
}
|
||||
|
||||
public String getSelectedLanguage() {
|
||||
try {
|
||||
final String text = selectedLanguage.getText();
|
||||
return text == null ? text : text.trim();
|
||||
} catch (NoSuchElementException ex) {
|
||||
// Fallback for Login v1
|
||||
return languageTextBase.getText();
|
||||
}
|
||||
}
|
||||
|
||||
public void selectLanguage(String language){
|
||||
try {
|
||||
WebElement langLink = languages.findElement(By.xpath("//option[text()[contains(.,'" + language + "')]]"));
|
||||
langLink.click();
|
||||
} catch (NoSuchElementException ex) {
|
||||
// Fallback for Login v1
|
||||
WebElement langLink = localeDropdownBase.findElement(By.xpath("//a[text()[contains(.,'" + language + "')]]"));
|
||||
langLink.click();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.openqa.selenium.support.FindBy;
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
public class ErrorPage extends AbstractPage {
|
||||
public class ErrorPage extends AbstractLoginPage {
|
||||
|
||||
@FindBy(className = "instruction")
|
||||
private WebElement errorMessage;
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.openqa.selenium.support.FindBy;
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
public class InfoPage extends AbstractPage {
|
||||
public class InfoPage extends AbstractLoginPage {
|
||||
|
||||
@FindBy(className = "instruction")
|
||||
private WebElement infoMessage;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.keycloak.testframework.ui.page;
|
||||
|
||||
import org.keycloak.testframework.ui.webdriver.ManagedWebDriver;
|
||||
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
public class LoginExpiredPage extends AbstractLoginPage {
|
||||
|
||||
public LoginExpiredPage(ManagedWebDriver driver) {
|
||||
super(driver);
|
||||
}
|
||||
|
||||
@FindBy(id = "loginRestartLink")
|
||||
private WebElement loginRestartLink;
|
||||
|
||||
@FindBy(id = "loginContinueLink")
|
||||
private WebElement loginContinueLink;
|
||||
|
||||
|
||||
public void clickLoginRestartLink() {
|
||||
loginRestartLink.click();
|
||||
}
|
||||
|
||||
public void clickLoginContinueLink() {
|
||||
loginContinueLink.click();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExpectedPageId() {
|
||||
return "login-login-page-expired";
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,11 @@ package org.keycloak.testframework.ui.page;
|
||||
import org.keycloak.testframework.ui.webdriver.ManagedWebDriver;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.NoSuchElementException;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
public class LoginPage extends AbstractPage {
|
||||
public class LoginPage extends AbstractLoginPage {
|
||||
|
||||
@FindBy(id = "username")
|
||||
private WebElement usernameInput;
|
||||
@@ -20,12 +21,23 @@ public class LoginPage extends AbstractPage {
|
||||
@FindBy(id = "rememberMe")
|
||||
private WebElement rememberMe;
|
||||
|
||||
@FindBy(linkText = "Forgot Password?")
|
||||
private WebElement resetPasswordLink;
|
||||
|
||||
@FindBy(className = "pf-m-success")
|
||||
private WebElement loginSuccessMessage;
|
||||
|
||||
@FindBy(id = "input-error-username")
|
||||
private WebElement userNameInputError;
|
||||
|
||||
public LoginPage(ManagedWebDriver driver) {
|
||||
super(driver);
|
||||
}
|
||||
|
||||
public void fillLogin(String username, String password) {
|
||||
usernameInput.clear();
|
||||
usernameInput.sendKeys(username);
|
||||
passwordInput.clear();
|
||||
passwordInput.sendKeys(password);
|
||||
}
|
||||
|
||||
@@ -54,6 +66,14 @@ public class LoginPage extends AbstractPage {
|
||||
return rememberMe.isSelected();
|
||||
}
|
||||
|
||||
public void resetPassword() {
|
||||
resetPasswordLink.click();
|
||||
}
|
||||
|
||||
public String getSuccessMessage() {
|
||||
return loginSuccessMessage != null ? loginSuccessMessage.getText() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExpectedPageId() {
|
||||
return "login-login";
|
||||
@@ -66,4 +86,13 @@ public class LoginPage extends AbstractPage {
|
||||
public void clearUsernameInput() {
|
||||
usernameInput.clear();
|
||||
}
|
||||
|
||||
public String getUsernameInputError() {
|
||||
try {
|
||||
return userNameInputError.getText();
|
||||
} catch (NoSuchElementException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.keycloak.testframework.ui.page;
|
||||
|
||||
import org.keycloak.testframework.ui.webdriver.ManagedWebDriver;
|
||||
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
public class LoginPasswordResetPage extends AbstractLoginPage {
|
||||
|
||||
@FindBy(id = "username")
|
||||
private WebElement usernameInput;
|
||||
|
||||
@FindBy(css = "[type=\"submit\"]")
|
||||
private WebElement submitButton;
|
||||
|
||||
@FindBy(id = "kc-reset-password-form")
|
||||
private WebElement formResetPassword;
|
||||
|
||||
public LoginPasswordResetPage(ManagedWebDriver driver) {
|
||||
super(driver);
|
||||
}
|
||||
|
||||
public void changePassword(String username) {
|
||||
usernameInput.clear();
|
||||
usernameInput.sendKeys(username);
|
||||
|
||||
submitButton.click();
|
||||
}
|
||||
|
||||
public String getFormUrl() {
|
||||
return formResetPassword.getAttribute("action");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExpectedPageId() {
|
||||
return "login-login-reset-password";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.openqa.selenium.support.FindBy;
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
public class LoginPasswordUpdatePage extends AbstractPage {
|
||||
public class LoginPasswordUpdatePage extends AbstractLoginPage {
|
||||
|
||||
@FindBy(id = "password-new")
|
||||
private WebElement newPasswordInput;
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.keycloak.testframework.ui.page;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.keycloak.testframework.ui.webdriver.ManagedWebDriver;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
public class OAuthGrantPage extends AbstractLoginPage {
|
||||
|
||||
// Locale-resolved built-in client scope consents
|
||||
public static final String PROFILE_CONSENT_TEXT = "User profile";
|
||||
public static final String EMAIL_CONSENT_TEXT = "Email address";
|
||||
public static final String ADDRESS_CONSENT_TEXT = "Address";
|
||||
public static final String PHONE_CONSENT_TEXT = "Phone number";
|
||||
public static final String OFFLINE_ACCESS_CONSENT_TEXT = "Offline Access";
|
||||
public static final String ROLES_CONSENT_TEXT = "User roles";
|
||||
|
||||
@FindBy(css = "[name=\"accept\"]")
|
||||
private WebElement acceptButton;
|
||||
@FindBy(css = "[name=\"cancel\"]")
|
||||
private WebElement cancelButton;
|
||||
|
||||
public OAuthGrantPage(ManagedWebDriver driver) {
|
||||
super(driver);
|
||||
}
|
||||
|
||||
public void accept(){
|
||||
acceptButton.click();
|
||||
}
|
||||
|
||||
public void cancel(){
|
||||
cancelButton.click();
|
||||
}
|
||||
|
||||
public List<String> getDisplayedGrants() {
|
||||
List<String> table = new ArrayList<>();
|
||||
WebElement divKcOauth = driver.findElement(By.id("kc-oauth"));
|
||||
for (WebElement li : divKcOauth.findElements(By.tagName("li"))) {
|
||||
WebElement span = li.findElement(By.tagName("span"));
|
||||
table.add(span.getText());
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
public void assertGrants(String... expectedGrants) {
|
||||
List<String> displayed = getDisplayedGrants();
|
||||
List<String> expected = Arrays.asList(expectedGrants);
|
||||
Assertions.assertTrue(displayed.containsAll(expected) && expected.containsAll(displayed),
|
||||
"Not matched grants. Displayed grants: " + displayed + ", expected grants: " + expected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExpectedPageId() {
|
||||
return "login-login-oauth-grant";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.keycloak.testframework.ui.page;
|
||||
|
||||
import org.keycloak.testframework.ui.webdriver.ManagedWebDriver;
|
||||
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
public class TermsAndConditionsPage extends AbstractLoginPage {
|
||||
|
||||
@FindBy(id = "kc-accept")
|
||||
private WebElement submitButton;
|
||||
|
||||
@FindBy(id = "kc-decline")
|
||||
private WebElement cancelButton;
|
||||
|
||||
public TermsAndConditionsPage(ManagedWebDriver driver) {
|
||||
super(driver);
|
||||
}
|
||||
|
||||
public void acceptTerms() {
|
||||
submitButton.click();
|
||||
}
|
||||
public void declineTerms() {
|
||||
cancelButton.click();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExpectedPageId() {
|
||||
return "login-terms";
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.keycloak.testframework.ui.webdriver;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.openqa.selenium.By;
|
||||
|
||||
public class AssertionUtils {
|
||||
|
||||
@@ -11,7 +12,8 @@ public class AssertionUtils {
|
||||
}
|
||||
|
||||
public void assertTitle(String title) {
|
||||
Assertions.assertEquals(title, managed.page().getTitle());
|
||||
String kcPageTitle = managed.findElement(By.id("kc-page-title")).getText();
|
||||
Assertions.assertEquals(title, kcPageTitle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package org.keycloak.testframework.ui.webdriver;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.keycloak.cookie.CookieType;
|
||||
|
||||
import org.openqa.selenium.Cookie;
|
||||
|
||||
public class CookieUtils {
|
||||
@@ -14,6 +18,18 @@ public class CookieUtils {
|
||||
managed.driver().manage().addCookie(cookie);
|
||||
}
|
||||
|
||||
public Cookie get(CookieType cookieType) {
|
||||
return managed.driver().manage().getCookieNamed(cookieType.getName());
|
||||
}
|
||||
|
||||
public Set<Cookie> getAll() {
|
||||
return managed.driver().manage().getCookies();
|
||||
}
|
||||
|
||||
public Cookie get(String name) {
|
||||
return managed.driver().manage().getCookieNamed(name);
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
managed.driver().manage().deleteAllCookies();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public class ManagedWebDriver {
|
||||
private AssertionUtils assertionUtils = new AssertionUtils(this);
|
||||
private CookieUtils cookieUtils = new CookieUtils(this);
|
||||
private PageUtils pageUtils = new PageUtils(this);
|
||||
private NavigateUtils navigateUtils = new NavigateUtils(this);
|
||||
private WaitUtils waitUtils = new WaitUtils(this);
|
||||
|
||||
public ManagedWebDriver(WebDriver driver) {
|
||||
@@ -65,6 +66,10 @@ public class ManagedWebDriver {
|
||||
return pageUtils;
|
||||
}
|
||||
|
||||
public NavigateUtils navigate() {
|
||||
return navigateUtils;
|
||||
}
|
||||
|
||||
public WaitUtils waiting() {
|
||||
return waitUtils;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.keycloak.testframework.ui.webdriver;
|
||||
|
||||
import org.keycloak.testframework.ui.page.AbstractPage;
|
||||
|
||||
public class NavigateUtils {
|
||||
|
||||
private final ManagedWebDriver driver;
|
||||
|
||||
NavigateUtils(ManagedWebDriver driver) {
|
||||
this.driver = driver;
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
driver.driver().navigate().refresh();
|
||||
}
|
||||
|
||||
public void backWithRefresh(AbstractPage expectedPage) {
|
||||
driver.driver().navigate().back();
|
||||
|
||||
String currentPageId = driver.page().getCurrentPageId();
|
||||
if (!expectedPage.getExpectedPageId().equals(currentPageId) && driver.getBrowserType().equals(BrowserType.CHROME)) {
|
||||
driver.driver().navigate().refresh();
|
||||
}
|
||||
|
||||
expectedPage.assertCurrent();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user