DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Accessibility Testing vs. Functional Testing
  • Accessibility Testing for Digital Products
  • Turbocharging Development: The Force of Automation Testing
  • Continuous Testing in the Era of Microservices and Serverless Architectures

Trending

  • How Large Tech Companies Architect Resilient Systems for Millions of Users
  • Unlocking AI Coding Assistants Part 4: Generate Spring Boot Application
  • A Developer's Guide to Mastering Agentic AI: From Theory to Practice
  • Breaking Bottlenecks: Applying the Theory of Constraints to Software Development
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Accessibility Testing Using Playwright

Accessibility Testing Using Playwright

Accessibility testing evaluates websites for compliance with accessibility standards to ensure usability for people with disabilities.

By 
Serhii Zabolenny user avatar
Serhii Zabolenny
·
Nov. 07, 23 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
1.7K Views

Join the DZone community and get the full member experience.

Join For Free

Today, I’d like to talk about accessibility testing using Playwright.

Accessibility testing refers to evaluating web applications or websites for compliance with accessibility standards, ensuring that they can be used by people with disabilities. Existing guidelines and other standards related to web accessibility Here are the links to them:

  • w3 Standard Guidelines
  • w3c Guidelines

The Accessibility Tree is used by assistive technology to augment or replace the existing UI for applications, as well as translate operations performed by the user into something that the application understands.

The Accessibility Tree

Playwright provides built-in support for accessibility testing by exposing methods and properties that allow you to interact with and inspect the accessibility features of web elements. You can use Playwright’s API to retrieve information about an element’s accessibility properties, such as its role, name, state, and description. This allows you to programmatically verify if the web application or website meets the required accessibility criteria. Additionally, Playwright has support for generating accessibility reports. You can use the page.accessibility.snapshot() method to capture a snapshot of the accessibility tree of a page. The Playwright site already has detailed documentation on using accessibility for tests, so that I won’t duplicate everything here. Still, I’d like to focus on the bottlenecks and possible solutions to some problems that I had on one of my projects.

Basics

To test Accessibility using Playwright, you need to additionally install the @axe-core/playwright library, with the help of which scanning of the webpage will take place.

Library of axe-core

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.

 
npm i @axe-core/playwright 


playwright


As you can see, everything happens in three steps in the test:

  1. Open the desired page.
  2. Scanning using AxBuilder()
  3. Comparison of obtained and expected results.

It is important to understand that the scanning is based on the principle of photography: if the page has modal windows or drop-down lists, they must first be opened to be tested. In addition, it is worth considering that the scan results contain not only violations, so for a correct comparison, you need to pass violations to expect(). If there is a violation, after the test, we will receive a report with detailed information about the violated rules and places where it happened, as well as information about possible solutions.

Configuration of the Analyzer

To get the optimal effect from testing, the analysis can be configured quite flexibly. This effect is achieved by using methods that allow you to set the level of recommendations or a set of rules and correct them by excluding irrelevant rules from the check.

It is also convenient to exclude a certain part of the page from the test and test only the part that is necessary. For myself, I chose the following configuration, wherein, include() depending on the specific test, the required selector or body will be passed by default. Playwright offers a number of sophisticated tools that let you run more complex a11y tests. For instance, the AxeBuilder class offers a wide range of axe setup configs. These settings can be specified by utilizing a Builder pattern.

Configuration of the Analyzer

Lighthouse for Accessibility Testing

Lighthouse is an open-source, automated tool from Google for improving the performance, quality, and correctness of your web apps. When auditing a page, Lighthouse runs a barrage of tests against the page and then generates a report on how well the page did. From here, you can use the failing tests as indicators of what you can do to improve your app.

To be able to use Lighthouse in Playwright tests, you can use the playwright-lighthouse package.

Lighthouse for Accessibility Testing


In my project, I have created a TS spec file for the purpose of running directly against Lighthouse.

running directly against Lighthouse

Reports

Same approach as for normal test cases. Playwright supports the configuration of different reports. In the case of accessibility tests, we just need to pass some additional information to the test itself.

Reports


As I said before, for my current project, I have a Lighthouse TS spec file, which I run from the command set in package.json.

 
npm run clean && npx playwright test tests/lighthouse.spec.ts --project=chromium


Conclusion

Playwright, in combination with the @axe-core library, is a fairly flexible and convenient tool for automated accessibility testing, although it does not cover all of its needs. As always, it depends on what your project needs. Playwright provides methods to access the accessibility tree of a page, allowing you to programmatically analyze and validate the properties of web elements. This makes it easier to identify and address accessibility issues.

However, it is true that the effectiveness of using any automation tool depends on who is using it, so always use it with common sense.

Builder pattern Functional testing Web accessibility Web application guidelines Testing

Published at DZone with permission of Serhii Zabolenny. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Accessibility Testing vs. Functional Testing
  • Accessibility Testing for Digital Products
  • Turbocharging Development: The Force of Automation Testing
  • Continuous Testing in the Era of Microservices and Serverless Architectures

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!