Accessibility Auditing with Axe for automated Web UI testing

undefined or mostly null.
Search for a command to run...

undefined or mostly null.
No comments yet. Be the first to comment.
In this series, I will share articles related to best practices for building and deploying applications on the web with the JavaScript and Python programming languages.
Heroku is a cloud-based, fully-managed platform as a service (Paas) for building, running, and managing apps. The platform is flexible and designed with DX support for you and your team’s preferred development style and to help you stay focused and p...
I wrote this article in December 2023 for an interview screening task and thought to share it today while clearing my drafts for some new content prep, just in case it's still helpful to someone out t

Hey! I’m super excited to announce that I have joined the Secretariat Team at the Digital Public Goods Alliance. In this role, I leverage my passion for open source and technical background to assess DPG applications, provide technical support and ad...

Creative designs have become more important than ever in the software ecosystem today with many industries and end-consumers having several use cases that require them to offer design editing solutions to either designers or end-consumers. Every busi...

With the rise of artificial intelligence (AI) and large language models (LLMs), it has become easier to solve different human problems than ever before. Even consumers with little to no technical expertise can benefit from AI. Humans can now automate...

Some years ago, GitHub introduced the new Profile README feature that allowed GitHub users to pin a markdown file on their profile using a special repository named after their GitHub username. Since then, developers have used this file as a quick por...

Accessibility has become a widely known and sort-for topic, with many developers and organizations advocating for the need to focus more on it towards building for the Next Billion Users.
An accessible site is one whose content can be accessed regardless of any user's impairments and whose functionality can also be operated by the most diverse range of users possible.
In this article, I'll introduce you to the Axe Library and how you can use it for auditing your application(s) on Web Browsers, CLI, Android, React.js, and Vue.js.
New to Web Accessibility? It will help if you read my previous article :).
A critical aspect of accessibility is Auditing. The best way to know if your application is inaccessible is to test and measure it; this way, you ascertain a need for any modification(s) before it is released to production.
Most developers Definition of Done excludes accessibility tasks, and I ran into this amazing tweet, which says it all.
Your application is not "Done" until you have tested it to ensure it complies with all the accessibility standards and guidelines.
Before you begin this tutorial, you'll need the following:
Technical Audit (TA) is an audit performed by an auditor, engineer or subject-matter expert evaluates deficiencies or areas of improvement in a process, system, or proposal ~ Wikipedia
Accessibility Audit (AA) is an audit performed by a developer, engineer, or accessibility expert, which evaluates deficiencies or areas of improvement in building websites that comply with the web accessibility guidelines.
As an enthusiastic developer with a great focus on accessibility, it would take a while for you to master all the guidelines and build an accessible application from scratch without any errors. But, just like learning any other skill, you need to practice, and eventually, you get used to these A11y standards. One way to practice here is to Audit your application during development and fix all flagged errors as they surface.
Checking for accessibility issues during Development is a great way to fix errors before production.
Some auditing libraries, such as axe and eslint-plugin-jsx-a11y are great tools you can use during the development of your React application to automatically check for accessibility issues and get notified as they surface.
Most accessibility tools are meant to be run on applications that have been deployed already, which can result in delays and serious debugging issues.
Axe is an accessibility testing engine for websites and other HTML-based user interfaces. It's fast, secure, lightweight, and was built to seamlessly integrate with any existing test environment so you can automate accessibility testing alongside your regular functional testing. ~ Axe Docs
One important feature of Axe is that it works with all modern browsers, tools, CLI, and testing environments, allowing you to check for accessibility issues during development in your terminal and after deployment.
Other automated auditing tools like Lighthouse and storybook-addon-a11y uses the Axe core engine which is open sourced.

Axe is available via some browser via extensions:
Axe also has an accessibility analysis tool and library for Android.
Axe also has a command-line interface for the aXe accessibility testing engine.
#npm
npm install @axe-core/cli -g
#yarn
yarn install @axe-core/cli -g
axe https://bolajiayodeji.com
axe https://bolajiayodeji.com --rules color-contrast
#npm
npm install --save-dev @axe-core/react
#yarn
yarn install --save-dev @axe-core/react
import React from 'react';
import ReactDOM from 'react-dom';
if (process.env.NODE_ENV !== 'production') {
let axe = require('@axe-core/react');
axe(React, ReactDOM, 1000);
} else {
ReactDOM.render(<App />, document.getElementById('root'));
}
let config = {
rules: [
{ id: 'heading-order', enabled: true },
{ id: 'label-title-only', enabled: true },
{ id: 'link-in-text-block', enabled: true },
{ id: 'region', enabled: true },
{ id: 'skip-link', enabled: true }
]
};
axe(React, ReactDOM, 1000, config);
The errors are logged with priority levels
@axe-core/react uses advanced console logging features and works best in the Chrome browser, with limited functionality in Safari and Firefox.
#npm
npm install -D vue-axe
#yarn
yarn add -D vue-axe
import Vue from 'vue'
if (process.env.NODE_ENV !== 'production') {
const VueAxe = require('vue-axe')
Vue.use(VueAxe, {
config: {
// ...
rules: [
{ id: 'heading-order', enabled: true },
{ id: 'label-title-only', enabled: true },
// and more
]
}
})
}
Axe logs issues to the DevTools console on the final rendered DOM, which is great. What if you want to see these errors right in your editor or terminal? Well, you would need to set up a linter that would allow you to see accessibility issues in your JSX.
# npm
npm install eslint --save-dev
# yarn
yarn add eslint --d
# npm
npm install eslint-plugin-jsx-a11y --save-dev
# yarn
yarn add eslint-plugin-jsx-a11y --dev
jsx-a11y to your .eslintrc configuration file{
"plugins": [
"jsx-a11y"
]
}
{
"extends": [
"plugin:jsx-a11y/recommended"
]
}
{
"extends": [
"plugin:jsx-a11y/strict"
]
}
See the difference between 'recommended' and 'strict' mode here

eslint-plugin-jsx-a11y will also display the errors in your DevTools console if you prove to be adamant :).

If your App was bootstrapped with Create-React-App, worry less, eslint-jsx-a11y is included already.
The web can only become an accessible, inclusive space if developers are empowered to take responsibility for accessibility testing and accessible coding practices. ~ Axe
Check out the following checklists to manually determine how accessible your site is and what accessible sites entail:
Want to build better Accessible JavaScript Applications with React and Gatsby? Check out this amazing course by Marcy on FrontendMasters.