Accessibility Automation Testing - Axe Core
Mohith Nayak
SDET | Test Automation | Software Testing | Java | Information Security | performance testing
In this article lets see how we can automate our Accessibility test cases using axe-core library. Lets me first define what is axe-core, how does it work and how can we automate our test cases by integrating it with selenium and java.
To know more about Accessibility testing and how can we test accessibility of applications manually, please go through this article which I have written earlier https://www.dhirubhai.net/pulse/accessibility-testing-mohith-nayak
Axe-core is an open-source accessibility testing library that can be used to scan websites and web applications for accessibility issues. It is compatible with a variety of programming languages, including JavaScript, Python, and Java(In this one we are only considering java for automation). Axe-core is a lightweight and fast library that can be easily integrated into existing testing frameworks.
Axe-core is based on the Web Content Accessibility Guidelines (WCAG) 2.1. It includes a number of rules that check for common accessibility issues, such as:
- Missing alt text for images
- Labels that do not match their controls
- Links that are not navigable with a keyboard
- Forms that are not accessible to screen readers
Axe-core is a powerful tool that can help you to improve the accessibility of your websites and web applications. It is a good choice for organizations that want to automate their accessibility testing.
Lets work on a sample code using axe-core, selenium and java
public class AxeCoreSelenium {
??public static void main(String args[]) {
??? public static void main(String[] args) {
// Create a new WebDriver instance
WebDriver driver = new ChromeDriver();
// Navigate to the website to be tested
driver.get("https://www.example.com");
// Create an AxeBuilder object
AxeBuilder axeBuilder = new AxeBuilder(driver);
// Run the axe-core scan
AxeResults axeResults = axeBuilder.analyze();
// Get the results of the scan
List<AxeResult> results = axeResults.getViolations();
// Log the results of the scan
领英推è
for (AxeResult result : results) {
System.out.println(result);
}
// Close the WebDriver instance
driver.close();
??}
}
Dependencies which we need to add for accessing axe-core along with latest selenium dependency:
<!-- https://mvnrepository.com/artifact/com.deque.html.axe-core/selenium -->
????<dependency>
??????<groupId>com.deque.html.axe-core</groupId>
??????<artifactId>selenium</artifactId>
??????<version>4.7.0</version>
????</dependency>
??<!-- https://mvnrepository.com/artifact/com.deque.html.axe-core/dequeutilites -->
????<dependency>
??????<groupId>com.deque.html.axe-core</groupId>
??????<artifactId>dequeutilites</artifactId>
??????<version>4.7.0</version>
????</dependency>
We can easily Integrate the above code with our existing selenium framework and implement it with multiple applications and environments.