Gathering detailed insights and metrics for cypress-axe
Gathering detailed insights and metrics for cypress-axe
Gathering detailed insights and metrics for cypress-axe
Gathering detailed insights and metrics for cypress-axe
@datacamp/waffles-cypress-axe-config
Waffles options for use within cypress-axe.
better-cypress-axe
Commands to help with Cypress-Axe
@onemrvapublic/cypress-axe-report
Generate an html accessibility report from the cypress-axe plugin
cypress-axe-core
Test accessibility with axe-core in Cypress
npm install cypress-axe
49.8
Supply Chain
78
Quality
74.3
Maintenance
100
Vulnerability
95.8
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
622 Stars
93 Commits
86 Forks
20 Watching
8 Branches
24 Contributors
Updated on 22 Nov 2024
Minified
Minified + Gzipped
TypeScript (56.17%)
JavaScript (37.72%)
HTML (6.1%)
Cumulative downloads
Total Downloads
Last day
-19.4%
68,516
Compared to previous day
Last week
-2.4%
404,295
Compared to previous week
Last month
3.6%
1,822,353
Compared to previous month
Last year
16.6%
21,232,777
Compared to previous year
Test accessibility with axe-core in Cypress.
cypress-axe
from npm:1npm install --save-dev cypress-axe
1npm install --save-dev cypress-axe@0.14.0
1npm install --save-dev cypress axe-core
1npm install --save-dev cypress@9.6.0 axe-core
cypress/support/e2e.js
file to include the cypress-axe commands by adding:cypress/support/index.js
file to include the cypress-axe commands by adding:1import 'cypress-axe'
If you’re using TypeScript, add cypress-axe types to your Cypress’ tsconfig.json
file:
1{ 2 "compilerOptions": { 3 "baseUrl": "./", 4 "target": "es5", 5 "lib": ["esnext", "dom"], 6 "types": ["cypress", "cypress-axe"] 7 }, 8 "include": ["."] 9}
This will inject the axe-core
runtime into the page under test. You must run this after a call to cy.visit()
and before you run the checkA11y
command.
You run this command with cy.injectAxe()
either in your test, or in a beforeEach
, as long as the visit
comes first.
1beforeEach(() => { 2 cy.visit('http://localhost:9000') 3 cy.injectAxe() 4})
The injectAxe
function receives an optional argument injectOptions
of type InjectOptions
.
This injectOptions
object can have a property axeCorePath
of type string
, which allows the user to specify the file from which axe-core
will be injected.
If axeCorePath
is not provided, the function will try to resolve the path to axe-core/axe.min.js
using the require.resolve
function, if it is available.
If require.resolve
is not available, the default path node_modules/axe-core/axe.min.js
will be used.
1beforeEach(() => {
2 cy.visit('http://localhost:9000')
3 cy.injectAxe({ axeCorePath: '<path-to-axe-core>' })
4})
To configure the format of the data used by aXe. This can be used to add new rules, which must be registered with the library to execute.
User specifies the format of the JSON structure passed to the callback of axe.run
Link - aXe Docs: axe.configure
1it('Has no detectable a11y violations on load (custom configuration)', () => { 2 // Configure aXe and test the page at initial load 3 cy.configureAxe({ 4 branding: { 5 brand: String, 6 application: String 7 }, 8 reporter: 'option', 9 checks: [Object], 10 rules: [Object], 11 locale: Object 12 }) 13 cy.checkA11y() 14})
This will run axe against the document at the point in which it is called. This means you can call this after interacting with your page and uncover accessibility issues introduced as a result of rendering in response to user actions.
Defines the scope of the analysis - the part of the DOM that you would like to analyze. This will typically be the document or a specific selector such as class name, ID, selector, etc.
Set of options passed into rules or checks, temporarily modifying them. This contrasts with axe.configure, which is more permanent.
The keys consist of those accepted by axe.run
's options argument, a custom includedImpacts
key, and retries
/interval
keys for retrying the check.
The includedImpacts
key is an array of strings that map to impact
levels in violations. Specifying this array will only include violations where the impact matches one of the included values. Possible impact values are "minor", "moderate", "serious", or "critical".
The retries
key is an integer that specifies how many times to retry the check if there are initial findings. The interval
key is an integer that specifies the number of milliseconds to wait between retries, and defaults to 1000
(one second). If retries
is not specified, the check will only be run once. Use this option to account for dynamic content that may not be fully loaded when the check is first run.
Filtering based on impact in combination with the skipFailures
argument allows you to introduce cypress-axe
into tests for a legacy application without failing in CI before you have an opportunity to address accessibility issues. Ideally, you would steadily move towards stricter testing as you address issues.
Allows you to define a callback that receives the violations for custom side-effects, such as adding custom output to the terminal.
NOTE: This respects the includedImpacts
filter and will only execute with violations that are included.
Disables assertions based on violations and only logs violations to the console output. This enabled you to see violations while allowing your tests to pass. This should be used as a temporary measure while you address accessibility violations.
Reference : https://github.com/component-driven/cypress-axe/issues/17
1// Basic usage
2it('Has no detectable a11y violations on load', () => {
3 // Test the page at initial load
4 cy.checkA11y()
5})
6
7// Applying a context and run parameters
8it('Has no detectable a11y violations on load (with custom parameters)', () => {
9 // Test the page at initial load (with context and options)
10 cy.checkA11y('.example-class', {
11 runOnly: {
12 type: 'tag',
13 values: ['wcag2a']
14 }
15 })
16})
17
18it('Has no detectable a11y violations on load (filtering to only include critical impact violations)', () => {
19 // Test on initial load, only report and assert for critical impact items
20 cy.checkA11y(null, {
21 includedImpacts: ['critical']
22 })
23})
24
25// Basic usage after interacting with the page
26it('Has no a11y violations after button click', () => {
27 // Interact with the page, then check for a11y issues
28 cy.get('button').click()
29 cy.checkA11y()
30})
31
32it('Only logs a11y violations while allowing the test to pass', () => {
33 // Do not fail the test when there are accessibility failures
34 cy.checkA11y(null, null, null, true)
35})
36
37it('Has no a11y violations after asynchronous load', () => {
38 // Retry the check if there are initial failures
39 cy.checkA11y(null, {
40 retries: 3,
41 interval: 100
42 })
43})
The violation callback parameter accepts a function and allows you to add custom behavior when violations are found.
This example adds custom logging to the terminal running Cypress, using cy.task
and the violationCallback
argument for cy.checkA11y
This registers a log
task as seen in the Cypress docs for cy.task as well as a table
task for sending tabular data to the terminal.
1module.exports = (on, config) => { 2 on('task', { 3 log(message) { 4 console.log(message) 5 6 return null 7 }, 8 table(message) { 9 console.table(message) 10 11 return null 12 } 13 }) 14}
Then we create a function that uses our tasks and pass it as the validationCallback
argument to cy.checkA11y
1// Define at the top of the spec file or just import it 2function terminalLog(violations) { 3 cy.task( 4 'log', 5 `${violations.length} accessibility violation${ 6 violations.length === 1 ? '' : 's' 7 } ${violations.length === 1 ? 'was' : 'were'} detected` 8 ) 9 // pluck specific keys to keep the table readable 10 const violationData = violations.map( 11 ({ id, impact, description, nodes }) => ({ 12 id, 13 impact, 14 description, 15 nodes: nodes.length 16 }) 17 ) 18 19 cy.task('table', violationData) 20} 21 22// Then in your test... 23it('Logs violations to the terminal', () => { 24 cy.checkA11y(null, null, terminalLog) 25})
This custom logging behavior results in terminal output like this:
When accessibility violations are detected, your test will fail and an entry titled "A11Y ERROR!" will be added to the command log for each type of violation found (they will be above the failed assertion). Clicking on those will reveal more specifics about the error in the DevTools console.
The project was created by Andy Van Slaars, and maintained by Artem Sapegin.
Thanks goes to these wonderful people (emoji key):
Samuel Custer 💻 📖 | Michael Toth 💻 | Nicholas Boll 💻 | Mike Davis 💻 | chit786 💻 📖 | Adrien courdavault 💻 | Brett Zamir 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT License, see the included License.md file.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
Found 14/27 approved changesets -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
13 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More