From 9e8a33710ff44a86afbd3c211723c6a38a0ef43b Mon Sep 17 00:00:00 2001 From: Vaclav Muzikar Date: Thu, 4 Feb 2016 12:48:06 +0100 Subject: [PATCH] KEYCLOAK-2451 Add Internationalization test --- .../console/page/fragment/Dropdown.java | 27 ++++++ .../console/page/realm/RealmSettings.java | 2 +- .../console/page/realm/ThemeSettings.java | 12 +++ .../realm/InternationalizationTest.java | 97 +++++++++++++++++++ 4 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/fragment/Dropdown.java create mode 100644 testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/InternationalizationTest.java diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/fragment/Dropdown.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/fragment/Dropdown.java new file mode 100644 index 0000000000..8661a04051 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/fragment/Dropdown.java @@ -0,0 +1,27 @@ +package org.keycloak.testsuite.console.page.fragment; + +import org.jboss.arquillian.graphene.fragment.Root; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +/** + * @author Vaclav Muzikar + */ +public class Dropdown { + @Root + private WebElement dropDownRoot; // MUST be .kc-dropdown + + @ArquillianResource + private WebDriver driver; + + public String getSelected() { + return dropDownRoot.findElement(By.xpath("./a")).getText(); + } + + public void selectByText(String text) { + String href = dropDownRoot.findElement(By.xpath("./ul/li/a[text()='" + text + "']")).getAttribute("href"); + driver.navigate().to(href); + } +} diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/RealmSettings.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/RealmSettings.java index 83b1a67526..347108dd6f 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/RealmSettings.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/RealmSettings.java @@ -10,7 +10,7 @@ import org.openqa.selenium.support.FindBy; */ public class RealmSettings extends AdminConsoleRealm { - @FindBy(xpath = "//div[@data-ng-controller='RealmTabCtrl']/ul") + @FindBy(className = "nav-tabs") private RealmTabs realmTabs; public RealmTabs tabs() { diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/ThemeSettings.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/ThemeSettings.java index c7160864dc..2392c7caa3 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/ThemeSettings.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/ThemeSettings.java @@ -17,6 +17,7 @@ */ package org.keycloak.testsuite.console.page.realm; +import org.keycloak.testsuite.console.page.fragment.OnOffSwitch; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.ui.Select; @@ -46,6 +47,9 @@ public class ThemeSettings extends RealmSettings { @FindBy(css = "#emailTheme") private Select emailThemeSelect; + @FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='internationalizationEnabled']]") + private OnOffSwitch internatEnabledSwitch; + public void changeLoginTheme(String themeName) { waitUntilElement(By.id("loginTheme")).is().present(); loginThemeSelect.selectByVisibleText(themeName); @@ -63,6 +67,14 @@ public class ThemeSettings extends RealmSettings { emailThemeSelect.selectByVisibleText(themeName); } + public void setInternatEnabled(boolean value) { + internatEnabledSwitch.setOn(value); + } + + public boolean isInternatEnabled() { + return internatEnabledSwitch.isOn(); + } + public void saveTheme() { primaryButton.click(); } diff --git a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/InternationalizationTest.java b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/InternationalizationTest.java new file mode 100644 index 0000000000..7cb21a6a8d --- /dev/null +++ b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/InternationalizationTest.java @@ -0,0 +1,97 @@ +package org.keycloak.testsuite.console.realm; + +import org.jboss.arquillian.graphene.page.Page; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.keycloak.testsuite.auth.page.AuthRealm; +import org.keycloak.testsuite.console.page.fragment.Dropdown; +import org.keycloak.testsuite.console.page.realm.ThemeSettings; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import static org.junit.Assert.*; +import static org.keycloak.testsuite.util.WaitUtils.*; +import static org.keycloak.testsuite.util.URLAssert.*; + +/** + * @author Vaclav Muzikar + */ +public class InternationalizationTest extends AbstractRealmTest { + @Page + private ThemeSettings themeSettingsPage; + + @FindBy(id = "kc-locale-dropdown") + private Dropdown localeDropdown; + + @Before + public void beforeInternationalizationTest() { + tabs().themes(); + themeSettingsPage.setInternatEnabled(true); + themeSettingsPage.saveTheme(); + realmSettingsPage.setAdminRealm(AuthRealm.TEST); + accountPage.setAuthRealm(testRealmPage); + deleteAllCookiesForTestRealm(); + deleteAllCookiesForMasterRealm(); + } + + @After + public void afterInternationalizationTest() { + testContext.setAdminLoggedIn(false); + } + + /** + * Change locale before login + */ + @Test + public void loginInternationalization() { + testRealmAdminConsolePage.navigateTo(); + + localeDropdown.selectByText("Español"); + assertLocale(".//label[@for='password']", "Contraseña"); // Password + + loginToTestRealmConsoleAs(testUser); + assertConsoleLocale("Temas"); + + accountPage.navigateTo(); + assertAccountLocale("Cuenta"); + } + + /** + * Change locale on the Account page + */ + @Test + public void accountInternationalization() { + accountPage.navigateTo(); + loginPage.form().login(testUser); + + localeDropdown.selectByText("Français"); + accountPage.navigateTo(); + assertAccountLocale("Compte"); + + deleteAllCookiesForTestRealm(); + + loginToTestRealmConsoleAs(testUser); + assertConsoleLocale("Thèmes"); + } + + private void assertConsoleLocale(String expected) { + assertCurrentUrlEquals(realmSettingsPage); + assertLocale(".//a[contains(@href,'/theme-settings')]", expected); // Themes + } + + private void assertAccountLocale(String expected) { + assertCurrentUrlEquals(accountPage); + assertLocale(".//div[contains(@class,'bs-sidebar')]/ul/li", expected); // Account + } + + private void assertLocale(String xpathSelector, String expected) { + WebElement element = driver.findElement(By.xpath(xpathSelector)); + assertLocale(element, expected); + } + + private void assertLocale(WebElement element, String expected) { + waitUntilElement(element); + assertEquals(expected, element.getText()); + } +}