Automated Accessibility Testing Is a Good Start - But You Need To Test Manually Too
Tags: a11y, webdev, react, testing
Published: 2021-02-14 17:19:27

"Is there a tool that checks if my website is accessible?" is a question I get asked sometimes. (Answer is no, by the way.) This usually leads to discussions about accessibility testing as part of the development flow. 

I've also had conversations with people who state that code is bad if it can't be tested with automated tests. I disagree. When it comes to testing a website's usability and accessibility, it can't be fully automated. There are too many factors that can't be programmatically checked yet.

This blog post will discuss a bit what I mean by automated accessibility testing and give some examples. I will also discuss why it's not enough and provide some tips and further reading on testing your website manually.

I also want to point out that it would be best to hire actual people with disabilities for testing. For example, a sighted tester, who does not use screen readers daily, can catch only so many problems on the site. However, I recognize that it's not always possible, so as developers, we need to know how to test (at least) basic things manually.

## Automated Accessibility Testing

There are multiple ways to conduct (semi) automated accessibility testing. It's possible to add plugins to linters and have a plugin that checks accessibility in the test environments. There are also automated tools in browsers, such as Lighthouse.

So when I'm referring to automated testing, I'm talking about everything that takes the code, parses it, and *programmatically* determines if the site is accessible or not. 

I'll introduce some of the tools that could be used for this. It's not an extensive list, but something I've used. And note: I'm doing mostly React-code, so these tools are from that world. 

### Linter

[`eslint-plugin-jsx-a11y`][5] is a plugin for eslint. It catches accessibility issues when developing. I use VSCode and eslint-extension, so if I write code that violates the rules, I get warnings in the code editor: 

![Coffee emoji without span-element with a warning: Emojis should be wrapped in <span>, have role=" img," and have an accessible description with aria-label or aria-labelledby.](https://dev-to-uploads.s3.amazonaws.com/i/gyikeim22b3j6ayaz63m.png)

This plugin helps to catch low hanging fruits, such as missing alt-attributes or missing attributes for a declared role. 

### Tests

Tests are another place where plugins can bring more accessibility insights. I've used two, depending on the test setup:  [jest-axe][9] and 
[cypress-axe][10]. They both add axe-core, [Deque's testing solution][13] to the testing environment. 

It's also possible to add Google's [Lighthouse][14] as an `npm`-module and include its tests to your CI/CD-pipeline. I bet other tools have these as well, but I haven't tried them.

### Tools in Browsers

There are multiple extensions for testing your site for accessibility. First, Google's [Lighthouse][14] is a way to run a test on your website. It's built-in to Chrome and can be added to Firefox as a plugin. It's not only for checking accessibility; as the introduction in their website says:

> Lighthouse is an open-source, automated tool for improving the quality of web pages. You can run it against any web page, public or requiring authentication. It has audits for performance, accessibility, progressive web apps, SEO and more. 

In Chrome, you can find it from the developer tools:

![Chrome Dev tools with "More tabs" open, and Lighthouse is rounded with a purple rectangle.](https://dev-to-uploads.s3.amazonaws.com/i/m9ibmjpgq33uy60cx9ya.png)

There are other tools as well: Deque's [aXe][8] and WebAIM's [Wave][7] are useful tools for checking the accessibility of a web page programmatically. They work a bit differently from each other. Axe runs the same checks as the testing library extensions mentioned above. The plugin and testing library extension both use `axe-core.` 

Wave, however, visualizes the elements where problems are. In my opinion, Wave's way of showing things can get pretty messy and hard to understand. Poking it for a while helped me learn how to navigate it, but it might be hard at first. You have been warned.

Axe and Lighthouse recognize that their results are not exhaustive, and they also list things to check manually. 

## Manual Testing

What I mean by manual testing is testing that is done, well, manually. This means using, for example, screen readers or keyboards - those tools that people with disabilities utilize to use the internet. 

I want to emphasize that if you aren't a screen reader (or other assistive technology) user, you can't actually know how users of those technologies use the web. So listen to the actual users if they say something. However, it's good to learn the basics of testing with these technologies. 

### Why Test Manually?

In 2019, the Act on the Provision of Digital Services came into effect in Finland. It means that all the public sector websites need to abide by the European Union's accessibility directive requirements. The transition period ended last fall, and there were some articles about if public sector websites are accessible or not.

What was pretty typical for the articles was that accessibility was often evaluated only with the Lighthouse's accessibility audit's score. Also, the questions for the representatives of cities and municipalities with lower scores were about improving that score.

I took a look and did a bit of digging on those sites having a score of 100. A quick test with a keyboard showed some problems immediately. For example, in one site, links were distinguished only by color. Looking into alt-texts also revealed some texts like "This is the logo for the site."  

These already fail some of the Success Criteria from WCAG 2.1, which is the requirement to pass. (To be exact: SC 1.4.1 and SC 1.1.1, respectively) 

Anyways, having a perfect accessibility score from Lighthouse is a start. By implementing those requirements, there are usually many benefits, and most of the low-hanging-fruits are caught. On the other hand, it's good to note that it's possible to [build a website with a perfect Lighthouse Score, which is also entirely inaccessible][1].

Depending on the study, [automated testing catches only about 15-40% of failures][2]. Good examples of things that automated tests miss are the quality of alt-texts. I mean, they can detect the presence of an alt-attributes, but they cannot detect if that text is actually descriptive or if the image is purely decorative and alt-text should be an empty string.  

### Tips on Testing Your Site Manually

#### Testing with Keyboard

The first and maybe the easiest way to test a website is to navigate it using only a keyboard — tab through the interface. See if you can tell where you are as you go. If the focus disappears, take note of those situations, and fix them. 

Also, remember that the expected keyboard navigation has some rules, other than just using <kbd>tab</kbd> and <kbd>enter</kbd> for navigation. For learning more about those, [WAI-ARIA Authoring Practices][15] provides a comprehensive list of these patterns. 
 
#### Screen Reader Testing

Another assistive technology to test with is a screen reader. I won't go into detail on how it's done because there are other helpful resources, and I am not an expert on the topic. For example, [WebAIM answers a lot of questions about screen reader testing][16]. 

#### Other Tools

Some other tools can help with manual testing. The first thing to list here is the browser's developer tools' accessibility features. They provide different ways to debug and test accessibility. Read more from different browsers' dev tools:
- [Chrome][6]
- [Firefox][17]
- [Safari][18]

A note, though: for some reason, you have to explicitly turn them on in Firefox and Safari. 

There are other helpful tools for manual testing as well. For example, [Web Developer-extension][3] is a useful tool for checking and visualizing aspects of a website. For example, you can show alt-texts on a website to check that they're meaningful:

![Web Developer-extension turned on and showing the alt text for the Hack the Planet announcement-image on Dev. The text says "alt=" Hack the Planet Icon.""](https://dev-to-uploads.s3.amazonaws.com/i/0aqsi5vaa7osvpobfmi0.png)

Another tool I have used is [tota11y][19] from Khan Academy. It's a bookmarklet that provides a tool for visualizing problems in things like headings, labels, color contrasts, and alt-attributes. One thing that I really like is the screen reader wand. With it, I can hover an item and see what the screen reader would read. It's an experimental feature and can't replace actual screen reader testing, but it's useful for quick checks.

![Mouse hovering a button with the text "Write a Post." Next to it's a textbox with the title "Screen Reader Wand" and text "Write a Post"](https://dev-to-uploads.s3.amazonaws.com/i/ffhpza7aho4u649tkw22.png)

## Wrapping Up

Automated accessibility tests and tools are a good start to catch accessibility failures from the code. These are usually so-called "low hanging fruits" and are relatively easy to fix. However, fixing just those problems doesn't guarantee accessibility.

Manual testing with assistive technology, such as keyboard and screen readers, gives more insight into the website's accessibility. For example, navigating the site using only a keyboard can be illuminating - you might find out that the site is not accessible for those users who don't use a mouse.

## Resources

### Tools
- [eslint-plugin-jsx-a11y][5]
- [jest-axe][9]
- [cypress-axe][10]
- [axe-core][13]
- [axe-extension][8]
- developer tools in [Chrome][6]
- developer tools in [Firefox][17]
- developer tools in [Safari][18]
- [Lighthouse][14]
- [Web Developer-extension][3]
- [tota11y][19]-bookmarklet

### Other Links
- [GOV.UK - What we found when we tested tools on the world's least-accessible webpage][2]
- [Manuel Matuzovic - The most inaccessible site possible with a perfect Lighthouse scoreboard][1]
- [WAI-ARIA Authoring Practices][15]
- [WebAIM - Testing with Screen Readers][16]

*Cover photo by [Surface][11] on [Unsplash][12]*

[1]: https://www.matuzo.at/blog/building-the-most-inaccessible-site-possible-with-a-perfect-lighthouse-score/
[2]: https://accessibility.blog.gov.uk/2017/02/24/what-we-found-when-we-tested-tools-on-the-worlds-least-accessible-webpage/
[3]: https://chrispederick.com/work/web-developer/
[4]: https://svenska.yle.fi/artikel/2020/09/10/manga-offentliga-webbsidor-har-dalig-tillganglighet-och-alldeles-snart-maste-det
[5]: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y
[6]: https://developers.google.com/web/tools/chrome-devtools/accessibility/reference#pane
[7]: https://wave.webaim.org/extension/
[8]: https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd 
[9]: https://github.com/nickcolley/jest-axe
[10]: https://github.com/component-driven/cypress-axe
[11]: https://unsplash.com/@surface
[12]: https://unsplash.com 
[13]: https://www.deque.com/axe/
[14]: https://developers.google.com/web/tools/lighthouse
[15]: https://www.w3.org/TR/wai-aria-practices-1.1/#aria_ex
[16]: https://webaim.org/articles/screenreader_testing/
[17]: https://developer.mozilla.org/en-US/docs/Tools/Accessibility_inspector
[18]: https://developer.apple.com/library/archive/documentation/Accessibility/Conceptual/AccessibilityMacOSX/OSXAXTestingApps.html
[19]: https://khan.github.io/tota11y/