Enterprise Web App Accessibility (feat. React)

Continuous Integration & Accessibility Test API

Marcy Sutton Todd

Marcy Sutton Todd

Principle Studios
Enterprise Web App Accessibility (feat. React)

Check out a free preview of the full Enterprise Web App Accessibility (feat. React) course

The "Continuous Integration & Accessibility Test API" Lesson is part of the full, Enterprise Web App Accessibility (feat. React) course featured in this preview video. Here's what you'd learn in this lesson:

Marcy discusses continuous integration (CI) and its importance in software development. They explain that CI involves merging code into a central repository and running automated tests to ensure that the code doesn't break anything. The instructor also mentions different tools and platforms that can be used for CI, and they touch on the topic of flaky tests and how to handle them. Additionally, they introduce the concept of using accessibility testing APIs like axe-core to automate accessibility testing in CI environments.


Transcript from the "Continuous Integration & Accessibility Test API" Lesson

>> CI, continuous integration. So this is a DevOps software development practice. I mean, we're probably all familiar with it, I just wanted to define it in case. So it where developers merge code together into a central place, we run builds automatically and the tests are run. So these tests could be all kinds of things, linters, TypeScript, type checks, automated tests for features.

We wanna make sure we aren't breaking other people's stuff. And this has become very commonplace. We don't have to use third party services anymore, even Circle CI or Travis. I think it's happening directly on GitHub, GitLab, Azure DevOps, wherever your code repository is. CI is just part of how we work most of the time now, it's really easy to set up.

So with hosted CI, at least there's on premise stuff, and this goes deep into DevOps. But in a nutshell, we write code and tests. There's an integration in our source repository to run some sort of checks, GitHub actions or however you hook this up. We enable CI builds for the project and then when we push our code, bam, it's gonna run all the tests.

You can run it when you submit a pull request, you can run it when you're doing a build pipeline, so we do all of those things in my work. And some platforms are easier than others, like Azure DevOps, not my fave. Jenkins, I tried setting up Jenkins a few times, that one was also a bit difficult.

CircleCI and Travis were just so much easier, I think they came later. But some tools are easier. I really miss GitHub, I have to be honest. [LAUGH] It's amazing. The pull request reviews are awesome, Azure DevOps could use some love. So I do have a screenshot of a pull request with some checks on it, and every repo is gonna have different tools.

These ones have some GitHub Actions looks like. This is Microsoft's Fluent UI component library. But for contributing to things, it is so nice to see checks, it just feels kind of comfy when you can satisfy some of those checks. It's caught me from adding some pain that my co-workers would have to deal with.

I work in an agency, so we're like, our merge strategy is the most complex I've ever seen, it's wild. So we have to really be on guard, so that we're not breaking things because of how our merge strategy works. So CI checks are everything in that environment. So CI can really help if you have some accessibility testing built-in, you can fail a build if you want, or at least have your coworkers know that something has broken.

So we can kind of spread that testing and awareness around when our team members are involved and you can track who broke the build. I've seen some teams will have it up on a monitor in their office, they kind of make a team thing out of it. I was lucky enough to have been in Mountain View in the angular office when I broke the build once, [LAUGH] and they had it on their monitor, it was kind of a badge of honor.

[LAUGH] But it is helpful for accountability, not only can you get blame on things, but in the moment, you can keep things from breaking, which is really nice. So should accessibility issues fail a build or not? It depends, it depends on what the accessibility issues are. If they're your feature tests that you wrote for your own components, yeah, those should probably fail a build.

If somebody changed an element, so it's not focusable anymore, or they deleted some code, or just something broke that used to work. If you have test coverage for it, and it broke, that should fail a build. If you have say, Cypress X or one of the accessibility test APIs running, you probably don't want that to fail a build.

Maybe in your first environment. But at least for us, we submit code, and then it has to go to a staging environment and then to UAT. I mean, it goes to like multiple steps of the way. So we don't really want things that are page level accessibility issues that may not even be in scope for what we just shipped, cropping up in a later environment.

We really need those to get handled earlier. So we wanna test it, we might wanna be more choosy and selective about when we run those. So linters and CI builds, I've seen type checks fail builds, and whether accessibility link rules should fail builds, that's another question. So it's worth experimenting, configuring your rules, add something that has just the right amount of friction and doesn't make everyone want it to turn it off, [LAUGH] like snapshots.

>> So I guess going back to CI, are there any types of tests that commonly flake out? Because I know at least my company, that's something we're trying to wrangle a little bit right now. And I wasn't sure if there were just some tests that sometimes they work, sometimes they don't, or if they're generally reliable, and as long as you have the test itself set up properly, it'll pass when it should be.

>> Yes, flaky tests, those are challenging. I have seen flaky tests where the test runs too quickly, and it hasn't had enough time to wait for things. Yeah, sometimes we need to use test Apis to wait, or we need to make our test more asynchronous or something. So I think the tooling's gotten a little bit better for that.

For things in accessibility, focus management can actually be the cause of flaky tests sometimes. Because you're trying to send focus to something, and well, for one in a CI environment depending on what tool you're running, it might be using virtual dom in memory. So, there might be some weirdness there.

But then the timing of things, when things are flaky, that means that they pass sometimes and fail others. If it passes locally, but always fails in CI or it only fails in CI part of the time, that's double flaky. Then you kind of have to think about, well, what's happening there?

It's something about the way that that test is being run, something about the way the UI is set up. Do I need to just wait for things more, or use use effect more, or something that's gonna put some guard rails around when that focus event will happen. I've had to do stuff as detailed as putting event listeners on CSS transitions to make sure stuff is ready.

So kinda dig into why it's failing and that might help narrow it down. Flaky tests are some of the hardest things though, it's like you just wanna punt on it and not think about it. [LAUGH] question?
>> Flaky tests, in my opinion, mostly happen in end-to-end tests
>> Yeah, there's more going on, there's more variables, things are slower.

So definitely the accessibility test APIs that we're gonna talk about now, they're slower. So things like Axe-Core, particularly the algorithm for color contrast, it's doing a lot. It's looking at the get-computed style of elements, which is very expensive as a check. And if you have to call it multiple times, that's even more computationally expensive.

And so for running things like axe, we probably only wanna run it at a page level, we're not gonna want to invoke it in every unit test or that's gonna be a very slow test suite. You can scope axe to only look at certain elements using the API, but it's still a big API to call in a unit test environment.

So my first bit of advice for using Axe-Core is to probably use it in Cypress. There's a bunch of different flavors though, and if you find it works in anywhere in your test suite without being too slow, go for it. But end-to-end tests can be kind of flaky.

So yeah, at least they have the wait for API in Cypress and in testing library. I think I always have to remember is that is that in Jest or in testing library? Sometimes it's hard to tell. So let's talk about using an accessibility testing API like Axe-Core. So we've seen Axe-Core in the browser extensions.

Axe-Core is a JavaScript library that you can call anywhere, really, but it's great for page-level accessibility tests. So when we run it in the Chrome extension or Firefox extension, we hear about things like color contrast, and the document language, and all of the markup on the page. So in an automated environment, we can mimic that by having a computer run it instead of us, manually pushing that button in the browser, we can run it with things like Cypress.

And it's pretty awesome. So what's nice about these APIs is that you don't have to write all of those accessibility tests. We're trying to get budget and support for doing the things we know most about, which are the features that are in our apps. Leadership probably doesn't wanna fund us to write accessibility testing rules at companies when that's not what we do.

So you can benefit from a lot of these rules by pulling in an accessibility testing API. And the accessibility companies like WebAiM and DQ, and there are many others, but they are dealing with accessibility compliance in the real world every day and they bake that knowledge into these libraries.

So if ARIA isn't working right somewhere or there's some detail, this folds into a concept of what's called accessibility supported. And so that's a big thing that these libraries are looking at, it's not just is it theoretically possible? They look at what's really working for people, so that's pretty cool.

And they keep really close track of WCAG and ARIA, they're in the W3Cs conformance task, accessibility conformance testing rules group. So there's a lot going on with these APIs. So for Axe and automated tests, there is an Axe-Core React library you could check out, but watch the performance of it.

Like I was saying, I think it could be a bit heavy-handed. There is just axe, if you have just testing and it would be hard to get Cypress or anything else, but you're like, but we have that right now. You could try out just axe, it's maintained by a community member as is Cypress Axe.

So I think there's even a fork of Cypress Axe just because people were having issues with it. So some of these are more well maintained than others, but I haven't had issues with Cypress X, so it's been pretty great. So these APIs can help you with things like HTML nesting and structuring issues, label and name computation that we really dug into earlier, incorrect ARIA usage which can be highly detailed.

If you grab one ARIA attribute, did you happen to get all of the other things that go with it like an ARIA menu role? They can really help with that, because they can be like, you forgot the required property that goes along with it. So that's nice. Color contrast, data table markup, they can look at that programmatically.

And then some viewport and zooming problems, if you've disabled page zooming or something, they can point that out.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now