Performing accessibility testing

We can perform basic accessibility checks by using tools such as Google's Accessibility Developer Tools (https://github.com/GoogleChrome/accessibility-developer-tools). We can inject the Google Accessibility testing library in a web page and perform the Accessibility Audit. This can be done automatically every time afterNavigatTo() is called. In the following code example, we will inject the axe_testing.js file provided by the Google Accessibility Developer Tools and perform the audit, which will print a report on the console:

public class IAmTheEventListener2 extends AbstractWebDriverEventListener {

@Override
public void beforeNavigateTo(String url, WebDriver driver) {
System.out.println("Before Navigate To "+ url);
}

@Override
public void beforeNavigateBack(WebDriver driver) {
System.out.println("Before Navigate Back. Right now I'm at "
+ driver.getCurrentUrl());
}

@Override
public void afterNavigateTo(String to, WebDriver driver) {

try {
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
URL url = new URL("https://raw.githubusercontent.com/GoogleChrome/" +

"accessibility-developer-tools/stable/dist/js/axs_testing.js");
String script = IOUtils.toString(url.openStream(), StandardCharsets.UTF_8);
jsExecutor.executeScript(script);
String report = (String) jsExecutor.executeScript("var results = axs.Audit.run();" +

"return axs.Audit.createReport(results);");
System.out.println("### Accessibility Report for " + driver.getTitle() + "####");
System.out.println(report);
System.out.println("### END ####");

} catch (MalformedURLException e) {

e.printStackTrace();
} catch (IOException e) {

e.printStackTrace();
}

}
}

The report is printed in the console, as shown here:

### Accessibility Report for Google####
*** Begin accessibility audit results ***
An accessibility audit found
Warnings:
Warning: AX_FOCUS_01 (These elements are focusable but either invisible or obscured by another element) failed on the following element:
#hplogo > DIV > .fOwUFe > A
See https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#-ax_focus_01--these-elements-are-focusable-but-either-invisible-or-obscured-by-another-element for more information.
Warning: AX_TEXT_02 (Images should have an alt attribute) failed on the following element:
#hplogo > DIV > .fOwUFe > A > .fJOQGe
See https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#-ax_text_02--images-should-have-an-alt-attribute-unless-they-have-an-aria-role-of-presentation for more information.
...
*** End accessibility audit results ***
### END ####

This report contains a collection of audit rules that check for common accessibility problems.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.5.239