Skip to main content

Automation Tests with Accessibility Tool using Playwright

This document walks you through the process of evaluating the accessibility of your website through the execution of automated tests using LambdaTest's Accessibility Tool.

Note : Accessibility Testing for Playwright is currently only supported on the Chrome browser (not Chromium-based browsers).

Prerequisites

Step-by-Step Guide to Trigger Your Test

Step 1: Setup Your Test Suite

You can use your own project to configure and test it. For demo purposes, we are using the sample repository.

sample repo

Download or Clone the code sample from the LambdaTest GitHub repository to run your tests.

Image View on GitHub

If you are using your own project, make sure you update the Hub endpoint in your tests file. By setting up the Hub endpoint, you establish the communication channel between your tests and the browser nodes, enabling effective test distribution and execution.

Configure the desired capabilities based on your test requirements. For example:

  const capabilities = {
'browserName': 'Chrome',
'browserVersion': 'latest',
'LT:Options': {
'platform': 'Windows 10',
'build': 'Playwright Accessibility',
'name': 'Playwright Accessibility',
'user': process.env.LT_USERNAME,
'accessKey': process.env.LT_ACCESS_KEY,
..//
}
}

You can generate capabilities for your test requirements with the help of our inbuilt 🔗 Capabilities Generator Tool.

Step 2: Establish User Authentication

Now, you need to export your environment variables LT_USERNAME and LT_ACCESS_KEY that are available in the LambdaTest Profile page.

Run the below mentioned commands in your terminal to setup the CLI and the environment variables.

export LT_USERNAME="undefined"
export LT_ACCESS_KEY="undefined"

Step 3: Configure the Necessary Capabilities

To enable the accessibility testing within your automated test suite, set the accessibility: true in your configuration file. You can also define other settings capabilities as described below.

const capabilities = {
"accessibility": true,
"accessibility.wcagVersion": "wcag21a",
"accessibility.bestPractice": false,
"accessibility.needsReview": true
};

Step 4: Add the following add-on Script

LambdaTest uses an internal Chrome extension that powers accessibility scans and generates accessibility reports. In your lambdatest-setup.js file add these three lines after your page creation command as shown below:

// Load the extension for report generation of the accessibility tests
await ltPage.goto("chrome://extensions/?id=johgkfjmgfeapgnbkmfkfkaholjbcnah");
const secondToggleButton = ltPage.locator('#crToggle').nth(0);
await secondToggleButton.click();

Step 5: Execute and Monitor your Test

Now execute your tests and visit the Automation Dashboard. Click on the Accessibility tab and check the report generated.

npx playwright test --config=./playwright.config.js
automation-dashboard

You can access the detailed accessibility report from the Accessibility Automation Reports Dashboard

automation-dashboard

Test across 3000+ combinations of browsers, real devices & OS.

Book Demo

Help and Support

Related Articles