Socket
Socket
Sign inDemoInstall

pa11y

Package Overview
Dependencies
Maintainers
7
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pa11y - npm Package Compare versions

Comparing version 6.0.0-alpha to 6.0.0

lib/browser.js

15

bin/pa11y.js

@@ -33,3 +33,3 @@ #!/usr/bin/env node

'-s, --standard <name>',
'the accessibility standard to use: Section508, WCAG2A, WCAG2AA (default), ' +
'the accessibility standard to use: WCAG2A, WCAG2AA (default), ' +
'WCAG2AAA – only used by htmlcs runner'

@@ -197,9 +197,14 @@ )

function loadReporter(name) {
let reporterMethods;
try {
reporterMethods = requireFirst([
`pa11y-reporter-${name}`,
path.join(process.cwd(), name)
], null);
if (['json', 'cli', 'csv', 'tsv'].includes(name)) {
reporterMethods = require(`../lib/reporters/${name}`);
} else {
reporterMethods = requireFirst([
`pa11y-reporter-${name}`,
path.join(process.cwd(), name)
], null);
}
} catch (error) {

@@ -206,0 +211,0 @@ console.error(

# Changelog
## 6.0.0 (2021-05-26)
* Test against WCAG 2.1 rules when using the default HTML_CodeSniffer runner.
* Upgrade puppeteer to v9, which reduces the number of browser crashes significantly.
* Remove support for testing against Section 508 standard.
* Replace `make` commands for testing with npm scripts (thanks @sonniesedge and @paazmaya).
* Integrate the built-in reporters with the pa11y repo (thanks @joeyciechanowicz).
* Improve resilience of tests and other quality of life improvements (thanks @sangitamane).
* Improve `--environment` output (thanks @ryhinchey).
* Drop support for Node.js versions older than 12.
## 6.0.0-alpha (2020-04-28)

@@ -8,2 +19,8 @@

## 5.3.1 (2021-04-01)
* Removed survey link from README.md file.
* Update the HTML_CodeSniffer runner so it doesn't install a version with WCAG 2.1 rules. See [pa11y/pa11y-runner-htmlcs@f22d3d1](https://github.com/pa11y/pa11y-runner-htmlcs/commit/f22d3d1d65bba415ca3415eb526123b301ecdd64) for details.
* Pin other dependencies in order to avoid problems like the one just mentioned.
## 5.3.0 (2019-09-30)

@@ -10,0 +27,0 @@

'use strict';
const runAction = require('./action');
const extend = require('node.extend');
const option = require('./option');
const fs = require('fs');
const path = require('path');
const {promisify} = require('util');

@@ -31,7 +30,7 @@ const pkg = require('../package.json');

let pa11yResults;
[url, options, callback] = parseArguments(url, options, callback);
[url, options, callback] = option.parseArguments(url, options, pa11y.defaults, callback);
try {
// Verify that the given options are valid
verifyOptions(options);
option.verifyOptions(options, pa11y.allowedStandards);

@@ -60,45 +59,2 @@ // Call the actual Pa11y test runner with

/**
* Parse arguments from the command-line to properly identify the url, options, and callback
* @private
* @param {String} url - The URL to run tests against.
* @param {Object} [options={}] - Options to change the way tests run.
* @param {Function} [callback] - An optional callback to use instead of promises.
* @returns {Array} the new values of url, options, and callback
*/
function parseArguments(url, options, callback) {
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
if (typeof url !== 'string') {
options = url;
url = options.url;
}
url = sanitizeUrl(url);
options = defaultOptions(options);
return [url,
options,
callback];
}
/**
* Default the passed in options using Pa11y's defaults.
* @private
* @param {Object} [options] - The options to apply defaults to.
* @returns {Object} Returns the defaulted options.
*/
function defaultOptions(options) {
options = extend({}, pa11y.defaults, options);
options.ignore = options.ignore.map(ignored => ignored.toLowerCase());
if (!options.includeNotices) {
options.ignore.push('notice');
}
if (!options.includeWarnings) {
options.ignore.push('warning');
}
return options;
}
/**
* Internal Pa11y test runner.

@@ -398,42 +354,2 @@ * @private

/**
* Verify that passed in options are valid.
* @private
* @param {Object} options - The options to verify.
* @returns {Undefined} Returns nothing.
* @throws {Error} Throws if options are not valid.
*/
function verifyOptions(options) {
if (!pa11y.allowedStandards.includes(options.standard)) {
throw new Error(`Standard must be one of ${pa11y.allowedStandards.join(', ')}`);
}
if (options.page && !options.browser) {
throw new Error('The page option must only be set alongside the browser option');
}
if (options.ignoreUrl && !options.page) {
throw new Error('The ignoreUrl option must only be set alongside the page option');
}
}
/**
* Sanitize a URL, ensuring it has a scheme. If the URL begins with a slash or a period,
* it will be resolved as a path against the current working directory. If the URL does
* begin with a scheme, it will be prepended with "http://".
* @private
* @param {String} url - The URL to sanitize.
* @returns {String} Returns the sanitized URL.
*/
function sanitizeUrl(url) {
if (/^\//i.test(url)) {
return `file://${url}`;
}
if (/^\./i.test(url)) {
return `file://${path.resolve(process.cwd(), url)}`;
}
if (!/^(https?|file):\/\//i.test(url)) {
return `http://${url}`;
}
return url;
}
/**
* Load a Pa11y runner module.

@@ -541,3 +457,2 @@ * @param {String} runner - The name of the runner.

pa11y.allowedStandards = [
'Section508',
'WCAG2A',

@@ -544,0 +459,0 @@ 'WCAG2AA',

{
"name": "pa11y",
"version": "6.0.0-alpha",
"version": "6.0.0",
"description": "Pa11y is your automated accessibility testing pal",

@@ -32,26 +32,24 @@ "keywords": [

"engines": {
"node": ">=8"
"node": ">=12"
},
"dependencies": {
"commander": "^3.0.2",
"envinfo": "^7.5.0",
"node.extend": "^2.0.2",
"p-timeout": "^2.0.1",
"pa11y-reporter-cli": "^2.0.0",
"pa11y-reporter-csv": "^2.0.0",
"pa11y-reporter-json": "^2.0.0",
"pa11y-runner-axe": "^2.0.0",
"pa11y-runner-htmlcs": "^2.0.0",
"puppeteer": "^2.1.1",
"semver": "^5.7.1"
"bfj": "~7.0.2",
"commander": "~6.2.1",
"envinfo": "~7.8.1",
"kleur": "~4.1.4",
"node.extend": "~2.0.2",
"p-timeout": "~4.1.0",
"pa11y-runner-axe": "~2.0.0",
"pa11y-runner-htmlcs": "~2.0.0",
"puppeteer": "~9.1.1",
"semver": "~7.3.5"
},
"devDependencies": {
"@rowanmanning/make": "^2.1.0",
"eslint": "^6.8.0",
"mocha": "^7.1.1",
"eslint": "^7.27.0",
"mocha": "^8.4.0",
"mockery": "^2.1.0",
"nyc": "^15.0.1",
"pa11y-lint-config": "^1.2.1",
"nyc": "^15.1.0",
"pa11y-lint-config": "^2.0.0",
"proclaim": "^3.6.0",
"sinon": "^9.0.2"
"sinon": "^11.1.0"
},

@@ -63,3 +61,8 @@ "main": "./lib/pa11y.js",

"scripts": {
"test": "make ci"
"lint": "eslint .",
"verify-coverage": "nyc check-coverage --lines 90 --functions 90 --branches 90",
"test-unit": "mocha --file test/unit/setup.test.js test/unit/**/*.test.js --recursive",
"test-coverage": "nyc --reporter=text --reporter=html mocha --file test/unit/setup.test.js test/unit/**/*.test.js --recursive",
"test-integration": "mocha --file test/integration/setup.test.js test/integration/**/*.test.js --recursive --timeout 10000 --slow 5000",
"test": "npm run test-coverage && npm run verify-coverage && npm run test-integration"
},

@@ -66,0 +69,0 @@ "files": [

@@ -0,5 +1,3 @@

# Pa11y
Pa11y
=====
Pa11y is your automated accessibility testing pal. It runs accessibility tests on your pages via the command line or Node.js, so you can automate your testing process.

@@ -15,3 +13,3 @@

```sh
pa11y http://example.com/
pa11y https://example.com/
```

@@ -24,3 +22,3 @@

pa11y('http://example.com/').then((results) => {
pa11y('https://example.com/').then((results) => {
// Do something with the results

@@ -32,43 +30,85 @@ });

Table Of Contents
-----------------
## Table of contents
- [Requirements](#requirements)
- [Command-Line Interface](#command-line-interface)
- [JavaScript Interface](#javascript-interface)
- [Configuration](#configuration)
- [Actions](#actions)
- [Runners](#runners)
- [Examples](#examples)
- [Common Questions and Troubleshooting](#common-questions-and-troubleshooting)
- [Tutorials and articles](#tutorials-and-articles)
- [Contributing](#contributing)
- [Support and Migration](#support-and-migration)
- [License](#license)
* [Table of contents](#table-of-contents)
* [Requirements](#requirements)
* [Linux and macOS](#linux-and-macos)
* [Windows](#windows)
* [Command-Line Interface](#command-line-interface)
* [Running Tests](#running-tests)
* [Exit Codes](#exit-codes)
* [Command-Line Configuration](#command-line-configuration)
* [Ignoring](#ignoring)
* [Reporters](#reporters)
* [JavaScript Interface](#javascript-interface)
* [Transforming the Results](#transforming-the-results)
* [Async/Await](#asyncawait)
* [Callback interface](#callback-interface)
* [Validating actions](#validating-actions)
* [Configuration](#configuration)
* [`actions` (array)](#actions-array)
* [`browser` (Browser) and `page` (Page)](#browser-browser-and-page-page)
* [`chromeLaunchConfig` (object)](#chromelaunchconfig-object)
* [`headers` (object)](#headers-object)
* [`hideElements` (string)](#hideelements-string)
* [`ignore` (array)](#ignore-array)
* [`ignoreUrl` (boolean)](#ignoreurl-boolean)
* [`includeNotices` (boolean)](#includenotices-boolean)
* [`includeWarnings` (boolean)](#includewarnings-boolean)
* [`level` (string)](#level-string)
* [`log` (object)](#log-object)
* [`method` (string)](#method-string)
* [`postData` (string)](#postdata-string)
* [`reporter` (string)](#reporter-string)
* [`rootElement` (element)](#rootelement-element)
* [`runners` (array)](#runners-array)
* [`rules` (array)](#rules-array)
* [`screenCapture` (string)](#screencapture-string)
* [`standard` (string)](#standard-string)
* [`threshold` (number)](#threshold-number)
* [`timeout` (number)](#timeout-number)
* [`userAgent` (string)](#useragent-string)
* [`viewport` (object)](#viewport-object)
* [`wait` (number)](#wait-number)
* [Actions](#actions)
* [Click Element](#click-element)
* [Set Field Value](#set-field-value)
* [Check/Uncheck Field](#checkuncheck-field)
* [Screen Capture](#screen-capture)
* [Wait For Fragment/Path/URL](#wait-for-fragmentpathurl)
* [Wait For Element State](#wait-for-element-state)
* [Wait For Element Event](#wait-for-element-event)
* [Navigate To URL](#navigate-to-url)
* [Runners](#runners)
* [Examples](#examples)
* [Basic Example](#basic-example)
* [Multiple Example](#multiple-example)
* [Actions Example](#actions-example)
* [Puppeteer Example](#puppeteer-example)
* [Common Questions and Troubleshooting](#common-questions-and-troubleshooting)
* [Tutorials and articles](#tutorials-and-articles)
* [Contributing](#contributing)
* [Support and Migration](#support-and-migration)
* [License](#license)
## Requirements
Requirements
------------
Pa11y requires [Node.js][node] 12+ to run. If you need support for older versions of Node.js, then please use [Pa11y 5.x][5.x].
Pa11y requires [Node.js][node] 8+ to run. If you need support for older versions of Node.js, then please use [Pa11y 4.x][4.x].
### Linux and macOS
### OS X
To install [Node.js][node] you can use [nvm][nvm]:
To install [Node.js][node] you can use [nvm][nvm]:
```sh
$ nvm install node
nvm install node
```
Alternatively on a Mac, you can install the required dependency with [Homebrew][brew]:
You can also install Node.js using a package manager like for example [Homebrew][brew]:
```sh
$ brew install node
brew install node
```
You can also download pre-built packages from the [Node.js][node] website.
Alternatively, you can also download pre-built packages from the [Node.js][node] website for your particular Operating System.
### Linux
Depending on your flavour of Linux, you should be able to use a package manager to install the required dependency. Alternatively download pre-built packages from the [Node.js][node] website.
### Windows

@@ -78,11 +118,7 @@

Windows 7 and below users approach with caution – we've been able to get Pa11y running but only after installing Visual Studio and the Windows SDK (as well as Git, and Python). The [Windows installation instructions for node-gyp][windows-install] are a good place to start. If you have had a better experience than this then please do share!
## Command-Line Interface
Command-Line Interface
----------------------
Install Pa11y globally with [npm][npm]:
```
```sh
npm install -g pa11y

@@ -93,3 +129,3 @@ ```

```
```sh
Usage: pa11y [options] <url>

@@ -101,3 +137,3 @@

-n, --environment output details about the environment Pa11y will run in
-s, --standard <name> the accessibility standard to use: Section508, WCAG2A, WCAG2AA (default), WCAG2AAA – only used by htmlcs runner
-s, --standard <name> the accessibility standard to use: WCAG2A, WCAG2AA (default), WCAG2AAA – only used by htmlcs runner
-r, --reporter <reporter> the reporter to use: cli (default), csv, json

@@ -125,9 +161,9 @@ -e, --runner <runner> the test runners to use: htmlcs (default), axe

```sh
pa11y https://example.com
```
pa11y http://example.com
```
Run an accessibility test against a file (absolute paths only, not relative):
```
```sh
pa11y ./path/to/your/file.html

@@ -138,23 +174,17 @@ ```

```sh
pa11y --reporter csv https://example.com > report.csv
```
pa11y --reporter csv http://example.com > report.csv
```
Run Pa11y with the Section508 ruleset:
```
pa11y --standard Section508 http://example.com
```
Run Pa11y using [aXe] as a [test runner](#runners):
```sh
pa11y --runner axe https://example.com
```
pa11y --runner axe http://example.com
```
Run Pa11y using [aXe] _and_ [HTML CodeSniffer][htmlcs] as [test runners](#runners):
```sh
pa11y --runner axe --runner htmlcs https://example.com
```
pa11y --runner axe --runner htmlcs http://example.com
```

@@ -165,12 +195,12 @@ ### Exit Codes

- `0`: Pa11y ran successfully, and there are no errors
- `1`: Pa11y failed run due to a technical fault
- `2`: Pa11y ran successfully but there are errors in the page
* `0`: Pa11y ran successfully, and there are no errors
* `1`: Pa11y failed run due to a technical fault
* `2`: Pa11y ran successfully but there are errors in the page
By default, only accessibility issues with a type of `error` will exit with a code of `2`. This is configurable with the `--level` flag which can be set to one of the following:
- `error`: exit with a code of `2` on errors only, exit with a code of `0` on warnings and notices
- `warning`: exit with a code of `2` on errors and warnings, exit with a code of `0` on notices
- `notice`: exit with a code of `2` on errors, warnings, and notices
- `none`: always exit with a code of `0`
* `error`: exit with a code of `2` on errors only, exit with a code of `0` on warnings and notices
* `warning`: exit with a code of `2` on errors and warnings, exit with a code of `0` on notices
* `notice`: exit with a code of `2` on errors, warnings, and notices
* `none`: always exit with a code of `0`

@@ -181,5 +211,5 @@ ### Command-Line Configuration

```sh
pa11y --config ./path/to/config.json https://example.com
```
pa11y --config ./path/to/config.json http://example.com
```

@@ -194,17 +224,17 @@ If any configuration is set both in a configuration file and also as a command-line option, the value set in the latter will take priority.

```sh
pa11y --ignore "issue-code-1;issue-code-2" https://example.com
```
pa11y --ignore "issue-code-1;issue-code-2" http://example.com
```
or by using the flag multiple times:
```sh
pa11y --ignore issue-code-1 --ignore issue-code-2 https://example.com
```
pa11y --ignore issue-code-1 --ignore issue-code-2 http://example.com
```
Pa11y can also ignore notices, warnings, and errors up to a threshold number. This might be useful if you're using CI and don't want to break your build. The following example will return exit code 0 on a page with 9 errors, and return exit code 2 on a page with 10 or more errors.
```sh
pa11y --threshold 10 https://example.com
```
pa11y --threshold 10 http://example.com
```

@@ -215,15 +245,13 @@ ### Reporters

- `cli`: output test results in a human-readable format
- `csv`: output test results as comma-separated values
- `json`: output test results as a JSON array
* `cli`: output test results in a human-readable format
* `csv`: output test results as comma-separated values
* `json`: output test results as a JSON array
* `tsv`: output test results as tab-separated values
The Pa11y team maintain some additional reporters which can be installed separately via `npm`:
The Pa11y team maintain an additional [`html`](https://github.com/pa11y/pa11y-reporter-html) reporter that can be installed separately via `npm` and can be used as an example of how to build more complex reporters.
- [`html`](https://github.com/pa11y/pa11y-reporter-html): output test results in a self-contained HTML format (`npm install pa11y-reporter-html`)
- [`tsv`](https://github.com/pa11y/pa11y-reporter-tsv): output test results as tab-separated values (`npm install pa11y-reporter-tsv`)
You can also write and publish your own reporters. Pa11y looks for reporters in your `node_modules` folder (with a naming pattern), and the current working directory. The first reporter found will be loaded. So with this command:
```sh
pa11y --reporter rainbows http://example.com
pa11y --reporter rainbows https://example.com
```

@@ -233,3 +261,3 @@

```
```sh
<cwd>/node_modules/pa11y-reporter-rainbows

@@ -255,6 +283,4 @@ <cwd>/rainbows

## JavaScript Interface
JavaScript Interface
--------------------
Install Pa11y with [npm][npm] or add to your `package.json`:

@@ -275,3 +301,3 @@

```js
pa11y('http://example.com/').then((results) => {
pa11y('https://example.com/').then((results) => {
// Do something with the results

@@ -284,3 +310,3 @@ });

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
// Options go here

@@ -301,3 +327,3 @@ }).then((results) => {

code: 'WCAG2AA.Principle1.Guideline1_1.1_1_1.H30.2',
context: '<a href="http://example.com/"><img src="example.jpg" alt=""/></a>',
context: '<a href="https://example.com/"><img src="example.jpg" alt=""/></a>',
message: 'Img element is the only content of the link, but is missing alt text. The alt text should describe the purpose of the link.',

@@ -331,3 +357,3 @@ selector: 'html > body > p:nth-child(1) > a',

try {
const results = await pa11y('http://example.com/');
const results = await pa11y('https://example.com/');
// Do something with the results

@@ -342,3 +368,3 @@ } catch (error) {

### Callback Interface
### Callback interface

@@ -348,3 +374,3 @@ If you would rather use callbacks than promises or `async`/`await`, then Pa11y supports this. This interface should be considered legacy, however, and may not appear in the next major version of Pa11y:

```js
pa11y('http://example.com/', (error, results) => {
pa11y('https://example.com/', (error, results) => {
// Do something with the results or handle the error

@@ -354,3 +380,3 @@ });

### Validating Actions
### Validating actions

@@ -366,6 +392,4 @@ Pa11y exposes a function which allows you to validate [action](#actions) strings before attempting to use them.

## Configuration
Configuration
-------------
Pa11y has lots of options you can use to change the way Headless Chrome runs, or the way your page is loaded. Options can be set either as a parameter on the `pa11y` function or in a [JSON configuration file](#command-line-configuration). Some are also available directly as [command-line options](#command-line-interface).

@@ -375,10 +399,8 @@

### `actions` (array) **BETA**
### `actions` (array)
Actions to be run before Pa11y tests the page. There are quite a few different actions available in Pa11y, the [Actions documentation](#actions) outlines each of them.
**Note:** actions are currently in a beta state and the API may change while we gather feedback.
```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
actions: [

@@ -413,3 +435,3 @@ 'set field #username to exampleUser',

pa11y('http://example.com/', {
pa11y('https://example.com/', {
browser: browser

@@ -430,3 +452,3 @@ });

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
chromeLaunchConfig: {

@@ -452,3 +474,3 @@ executablePath: '/path/to/Chrome',

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
headers: {

@@ -467,3 +489,3 @@ Cookie: 'foo=bar'

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
hideElements: '.advert, #modal, div[aria-role=presentation]'

@@ -478,3 +500,3 @@ });

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
ignore: [

@@ -496,3 +518,3 @@ 'WCAG2AA.Principle3.Guideline3_1.3_1_1.H57.2'

pa11y('http://example.com/', {
pa11y('https://example.com/', {
ignoreUrl: true,

@@ -511,3 +533,3 @@ page: page,

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
includeNotices: true

@@ -524,3 +546,3 @@ });

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
includeWarnings: true

@@ -549,3 +571,3 @@ });

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
log: {

@@ -566,3 +588,3 @@ debug: console.log,

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
method: 'POST'

@@ -579,3 +601,3 @@ });

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
headers: {

@@ -592,3 +614,3 @@ 'Content-Type': 'application/x-www-form-urlencoded'

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
headers: {

@@ -621,6 +643,7 @@ 'Content-Type': 'application/json'

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
rootElement: '#main'
});
```
Defaults to `null`, meaning the full document will be tested. If the specified root element isn't found, the full document will be tested.

@@ -633,3 +656,3 @@

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
runners: [

@@ -652,6 +675,6 @@ 'axe',

An array of WCAG 2.0 guidelines that you'd like to include to the current standard. Note: These won't be applied to `Section508` standard. You can find the codes for each guideline in the [HTML Code Sniffer WCAG2AAA ruleset][htmlcs-wcag2aaa-ruleset]. **Note:** only used by htmlcs runner.
An array of WCAG 2.0 guidelines that you'd like to include to the current standard. You can find the codes for each guideline in the [HTML Code Sniffer WCAG2AAA ruleset][htmlcs-wcag2aaa-ruleset]. **Note:** only used by htmlcs runner.
```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
rules: [

@@ -668,3 +691,3 @@ 'Principle1.Guideline1_3.1_3_1_AAA'

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
screenCapture: `${__dirname}/my-screen-capture.png`

@@ -678,7 +701,7 @@ });

The accessibility standard to use when testing pages. This should be one of `Section508`, `WCAG2A`, `WCAG2AA`, or `WCAG2AAA`. **Note:** only used by htmlcs runner.
The accessibility standard to use when testing pages. This should be one of `WCAG2A`, `WCAG2AA`, or `WCAG2AAA`. **Note:** only used by htmlcs runner.
```js
pa11y('http://example.com/', {
standard: 'Section508'
pa11y('https://example.com/', {
standard: 'WCAG2A'
});

@@ -708,3 +731,3 @@ ```

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
timeout: 500

@@ -721,3 +744,3 @@ });

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
userAgent: 'A11Y TESTS'

@@ -734,3 +757,3 @@ });

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
viewport: {

@@ -759,3 +782,3 @@ width: 320,

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
wait: 500

@@ -767,10 +790,8 @@ });

## Actions
Actions
-------
Actions are additional interactions that you can make Pa11y perform before the tests are run. They allow you to do things like click on a button, enter a value in a form, wait for a redirect, or wait for the URL fragment to change:
```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
actions: [

@@ -799,3 +820,3 @@ 'click element #tab-1',

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
actions: [

@@ -806,2 +827,3 @@ 'click element #tab-1'

```
You can use any valid [query selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector), including classes and types.

@@ -814,3 +836,3 @@

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
actions: [

@@ -827,3 +849,3 @@ 'set field #fullname to John Doe'

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
actions: [

@@ -841,3 +863,3 @@ 'check field #terms-and-conditions',

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
actions: [

@@ -853,8 +875,8 @@ 'screen capture example.png'

- `wait for fragment to be <fragment>` (including the preceding `#`)
- `wait for fragment to not be <fragment>` (including the preceding `#`)
- `wait for path to be <path>` (including the preceding `/`)
- `wait for path to not be <path>` (including the preceding `/`)
- `wait for url to be <url>`
- `wait for url to not be <url>`
* `wait for fragment to be <fragment>` (including the preceding `#`)
* `wait for fragment to not be <fragment>` (including the preceding `#`)
* `wait for path to be <path>` (including the preceding `/`)
* `wait for path to not be <path>` (including the preceding `/`)
* `wait for url to be <url>`
* `wait for url to not be <url>`

@@ -864,3 +886,3 @@ E.g.

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
actions: [

@@ -877,6 +899,6 @@ 'click element #login-link',

- `wait for element <selector> to be added`
- `wait for element <selector> to be removed`
- `wait for element <selector> to be visible`
- `wait for element <selector> to be hidden`
* `wait for element <selector> to be added`
* `wait for element <selector> to be removed`
* `wait for element <selector> to be visible`
* `wait for element <selector> to be hidden`

@@ -886,3 +908,3 @@ E.g.

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
actions: [

@@ -900,3 +922,3 @@ 'click element #tab-2',

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
actions: [

@@ -914,5 +936,5 @@ 'click element #tab-2',

```js
pa11y('http://example.com/', {
pa11y('https://example.com/', {
actions: [
'navigate to http://another-example.com'
'navigate to https://another-example.com'
]

@@ -922,20 +944,18 @@ });

## Runners
Runners
-------
Pa11y supports multiple test runners which return different results. The built-in test runners are:
- `axe`: run tests using [aXe-core][axe].
- `htmlcs` (default): run tests using [HTML CodeSniffer][htmlcs]
* `axe`: run tests using [aXe-core][axe].
* `htmlcs` (default): run tests using [HTML CodeSniffer][htmlcs]
You can also write and publish your own runners. Pa11y looks for runners in your `node_modules` folder (with a naming pattern), and the current working directory. The first runner found will be loaded. So with this command:
```sh
pa11y --runner my-testing-tool https://example.com
```
pa11y --runner my-testing-tool http://example.com
```
The following locations will be checked:
```
```sh
<cwd>/node_modules/pa11y-runner-my-testing-tool

@@ -966,6 +986,6 @@ <cwd>/node_modules/my-testing-tool

- `options`: Options specified in the test runner
- `pa11y`: The Pa11y test runner, which includes some helper methods:
- `pa11y.getElementContext(element)`: Get a short HTML context snippet for an element
- `pa11y.getElementSelector(element)`: Get a unique selector with which you can select this element in a page
* `options`: Options specified in the test runner
* `pa11y`: The Pa11y test runner, which includes some helper methods:
* `pa11y.getElementContext(element)`: Get a short HTML context snippet for an element
* `pa11y.getElementSelector(element)`: Get a unique selector with which you can select this element in a page

@@ -984,6 +1004,4 @@ The `run` method _must_ resolve with an array of Pa11y issues. These follow the format:

## Examples
Examples
--------
### Basic Example

@@ -1005,22 +1023,12 @@

## Common Questions and Troubleshooting
Common Questions and Troubleshooting
------------------------------------
See our [Troubleshooting guide](TROUBLESHOOTING.md) to get the answers to common questions about Pa11y, along with some ideas to help you troubleshoot any problems.
## Tutorials and articles
Tutorials and articles
------------------------------------
You can find some useful tutorials and articles in the [Tutorials section](https://pa11y.org/tutorials/) of [pa11y.org](https://pa11y.org/).
Here are some useful articles written by Pa11y users and contributors:
## Contributing
- [Accessibility Testing with Pa11y](https://bitsofco.de/pa11y/)
- [Using actions in Pa11y](http://hollsk.co.uk/posts/view/using-actions-in-pa11y)
- [Introduction to Accessibility Testing With Pa11y](http://cruft.io/posts/accessibility-testing-with-pa11y/)
Contributing
------------
There are many ways to contribute to Pa11y, we cover these in the [contributing guide](CONTRIBUTING.md) for this repo.

@@ -1030,6 +1038,7 @@

Please write unit tests for your code, and check that everything works by running the following before opening a <abbr title="pull request">PR</abbr>:
Please write unit tests for your code, and check that everything works by running the following before opening a pull request:
```sh
make ci
npm run lint
npm test
```

@@ -1040,7 +1049,7 @@

```sh
make verify # Verify all of the code (ESLint)
make test # Run all tests
make test-unit # Run the unit tests
make test-unit-coverage # Run the unit tests with coverage
make test-integration # Run the integration tests
npm run lint # Verify all of the code (ESLint)
npm test # Run all tests
npm run test-unit # Run the unit tests
npm run coverage # Run the unit tests with coverage
npm run test-integration # Run the integration tests
```

@@ -1050,4 +1059,3 @@

Support and Migration
---------------------
## Support and Migration

@@ -1060,3 +1068,4 @@ Pa11y major versions are normally supported for 6 months after their last minor release. This means that patch-level changes will be added and bugs will be fixed. The table below outlines the end-of-support dates for major versions, and the last minor release for that version.

| :-------------- | :------------ | :----------------- | :--------------- | :--------------- |
| :heart: | 5 | N/A | 8+ | N/A |
| :heart: | 6 | N/A | 12+ | N/A |
| :warning: | 5 | 5.3 | 8+ | 2021-11-25 |
| :skull: | 4 | 4.13 | 4–8 | 2018-08-15 |

@@ -1069,15 +1078,17 @@ | :skull: | 3 | 3.8 | 0.12–6 | 2016-12-05 |

License
-------
## License
Pa11y is licensed under the [Lesser General Public License (LGPL-3.0)][info-license].<br/>
Copyright &copy; 2013–2019, Team Pa11y and contributors
Pa11y is licensed under the [Lesser General Public License (LGPL-3.0)][info-license].
Copyright &copy; 2013–2021, Team Pa11y and contributors
[1.0-json-reporter]: https://github.com/pa11y/reporter-1.0-json
[4.x]: https://github.com/pa11y/pa11y/tree/4.x
[async]: https://github.com/caolan/async
[5.x]: https://github.com/pa11y/pa11y/tree/5.x
[axe]: https://www.axe-core.org/
[brew]: http://mxcl.github.com/homebrew/
[brew]: https://mxcl.github.com/homebrew/
[htmlcs-wcag2aaa-ruleset]: https://github.com/pa11y/pa11y/wiki/HTML-CodeSniffer-Rules
[node]: http://nodejs.org/
[htmlcs]: https://squizlabs.github.io/HTML_CodeSniffer/
[info-build]: https://github.com/pa11y/pa11y.github.io/actions/workflows/build-and-test.yml
[info-license]: LICENSE
[info-node]: package.json
[info-npm]: https://www.npmjs.com/package/pa11y
[node]: https://nodejs.org/
[npm]: https://www.npmjs.com/

@@ -1091,13 +1102,5 @@ [nvm]: https://github.com/nvm-sh/nvm

[semver range]: https://github.com/npm/node-semver#ranges
[sidekick-proposal]: https://github.com/pa11y/sidekick/blob/master/PROPOSAL.md
[htmlcs]: http://squizlabs.github.com/HTML_CodeSniffer/
[windows-install]: https://github.com/TooTallNate/node-gyp#installation
[info-license]: LICENSE
[info-node]: package.json
[info-npm]: https://www.npmjs.com/package/pa11y
[info-build]: https://travis-ci.org/pa11y/pa11y
[shield-build]: https://github.com/pa11y/pa11y/actions/workflows/build-and-test.yml/badge.svg
[shield-license]: https://img.shields.io/badge/license-LGPL%203.0-blue.svg
[shield-node]: https://img.shields.io/node/v/pa11y.svg
[shield-npm]: https://img.shields.io/npm/v/pa11y.svg
[shield-build]: https://img.shields.io/travis/pa11y/pa11y/master.svg
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc