Merge pull request #2177 from vmuzikar/master

KEYCLOAK-2451 Add Internationalization test
This commit is contained in:
Stian Thorgersen 2016-02-04 16:35:24 +01:00
commit d8d96e5ec1
4 changed files with 137 additions and 1 deletions

View file

@ -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 <vmuzikar@redhat.com>
*/
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);
}
}

View file

@ -10,7 +10,7 @@ import org.openqa.selenium.support.FindBy;
*/ */
public class RealmSettings extends AdminConsoleRealm { public class RealmSettings extends AdminConsoleRealm {
@FindBy(xpath = "//div[@data-ng-controller='RealmTabCtrl']/ul") @FindBy(className = "nav-tabs")
private RealmTabs realmTabs; private RealmTabs realmTabs;
public RealmTabs tabs() { public RealmTabs tabs() {

View file

@ -17,6 +17,7 @@
*/ */
package org.keycloak.testsuite.console.page.realm; 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.FindBy;
import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.Select;
@ -46,6 +47,9 @@ public class ThemeSettings extends RealmSettings {
@FindBy(css = "#emailTheme") @FindBy(css = "#emailTheme")
private Select emailThemeSelect; private Select emailThemeSelect;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='internationalizationEnabled']]")
private OnOffSwitch internatEnabledSwitch;
public void changeLoginTheme(String themeName) { public void changeLoginTheme(String themeName) {
waitUntilElement(By.id("loginTheme")).is().present(); waitUntilElement(By.id("loginTheme")).is().present();
loginThemeSelect.selectByVisibleText(themeName); loginThemeSelect.selectByVisibleText(themeName);
@ -63,6 +67,14 @@ public class ThemeSettings extends RealmSettings {
emailThemeSelect.selectByVisibleText(themeName); emailThemeSelect.selectByVisibleText(themeName);
} }
public void setInternatEnabled(boolean value) {
internatEnabledSwitch.setOn(value);
}
public boolean isInternatEnabled() {
return internatEnabledSwitch.isOn();
}
public void saveTheme() { public void saveTheme() {
primaryButton.click(); primaryButton.click();
} }

View file

@ -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 <vmuzikar@redhat.com>
*/
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());
}
}