Improve a11y by providing the current language (#20213)

This commit is contained in:
Jay Linski 2023-05-30 19:46:14 +02:00 committed by GitHub
parent 8aeee928e8
commit 403632438a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 5 deletions

View file

@ -38,6 +38,9 @@ public class LoginPage extends LanguageComboboxAwarePage {
@ArquillianResource
protected OAuthClient oauth;
@FindBy(xpath = "//html")
protected WebElement htmlRoot;
@FindBy(id = "username")
protected WebElement usernameInput;
@ -68,7 +71,6 @@ public class LoginPage extends LanguageComboboxAwarePage {
@FindBy(className = "alert-success")
private WebElement loginSuccessMessage;
@FindBy(className = "alert-info")
private WebElement loginInfoMessage;
@ -109,12 +111,15 @@ public class LoginPage extends LanguageComboboxAwarePage {
usernameInput.sendKeys(username);
passwordInput.clear();
clickLink(submitButton);
}
public void missingUsername() {
clearUsernameInputAndWaitIfNecessary();
clickLink(submitButton);
}
public String getHtmlLanguage() {
return htmlRoot.getAttribute("lang");
}
public String getUsername() {
@ -168,6 +173,7 @@ public class LoginPage extends LanguageComboboxAwarePage {
public String getSuccessMessage() {
return loginSuccessMessage != null ? loginSuccessMessage.getText() : null;
}
public String getInfoMessage() {
try {
return getTextFromElement(loginInfoMessage);
@ -176,7 +182,6 @@ public class LoginPage extends LanguageComboboxAwarePage {
}
}
public boolean isCurrent() {
String realm = "test";
return isCurrent(realm);

View file

@ -120,6 +120,16 @@ public class LoginPageTest extends AbstractI18NTest {
assertEquals("Deutsch", loginPage.getLanguageDropdownText());
}
@Test
public void htmlLangAttribute() {
loginPage.open();
assertEquals("en", loginPage.getHtmlLanguage());
oauth.uiLocales("de");
loginPage.open();
assertEquals("de", loginPage.getHtmlLanguage());
}
@Test
public void acceptLanguageHeader() throws IOException {
try(CloseableHttpClient httpClient = (CloseableHttpClient) new HttpClientBuilder().build()) {

View file

@ -1,6 +1,6 @@
<#macro mainLayout active bodyClass>
<!doctype html>
<html>
<html<#if realm.internationalizationEnabled> lang="${locale.currentLanguageTag}"</#if>>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

View file

@ -1,6 +1,6 @@
<#macro registrationLayout bodyClass="" displayInfo=false displayMessage=true displayRequiredFields=false>
<!DOCTYPE html>
<html class="${properties.kcHtmlClass!}">
<html class="${properties.kcHtmlClass!}"<#if realm.internationalizationEnabled> lang="${locale.currentLanguageTag}"</#if>>
<head>
<meta charset="utf-8">