npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cypress-puppeteer-a11y

v1.0.4

Published

A Cypress plugin for validating accessibility (a11y) using Puppeteer

Downloads

259

Readme

Cypress a11y plugin

This plugin allows teams to fetch the accessibility (a11y) tree using Puppeteer.

Installation

To install the latest version of the plugin, run the following command:

npm install cypress-puppeteer-a11y@{version} or
npm install cypress-puppeteer-a11y@latest

Setup

After installing the plugin, you need to add it to your cypress.config.js file.

1. Update cypress.config.js:

In your cypress.config.js file, you need to add the plugin configuration:

const { fetchA11yTreeForPage, findDuplicates, fetchA11yTreeForDialog, fetchA11yTreeForMenu } = require('cypress-puppeteer-a11y/cypress/plugins/a11yPlugin.js');

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on("task", {
        fetchA11yTreeForPage({ url, cookies, localStorageData }) {
          return fetchA11yTreeForPage(url, cookies, localStorageData);
        },
        findDuplicates(a11yTree) {
          return findDuplicates(a11yTree);
        },
        fetchA11yTreeForDialog({ cookies, localStorageData, url, actions }) {
          return fetchA11yTreeForDialog({
            cookies,
            localStorageData,
            url,
            actions,
          });
        },
        fetchA11yTreeForMenu({ cookies, localStorageData, url, actions, menuSelector }) {
          return fetchA11yTreeForMenu({
            cookies,
            localStorageData,
            url,
            actions,
            menuSelector
          });
        },
      });

      // Return the updated config object
      return config;
    },
    // other config options
  },
});

Plugin Validation

To validate if the plugin is working correctly, you can run the provided validation script. This script verifies the functionality of core tasks, including fetching accessibility trees and detecting duplicates.

Steps to Run Plugin Validation

  1. Ensure the Plugin is Set Up Correctly: Follow the setup instructions above to configure the plugin in your cypress.config.js.
  2. Navigate to the Scripts Folder: The validation script is located in the scripts folder of your project.
  3. Run the Validation Script:
node scripts/validateA11yPlugin.js

Example Validation Script Output

Starting Plugin Validation...

Navigating to https://en.wikipedia.org/wiki/World_history...
Fetched Cookies: [ ...cookie details... ]
Fetched Local Storage: { ...local storage details... }
Validating fetchA11yTreeForPage...
Accessibility Tree for Page: { ...tree details... }
✅ fetchA11yTreeForPage executed successfully.

Navigating to https://example.com...
Fetched Cookies: [ ...cookie details... ]
Fetched Local Storage: { ...local storage details... }
Validating fetchA11yTreeForMenu...
Accessibility Tree for Menu: { ...tree details... }
✅ fetchA11yTreeForMenu executed successfully.

Navigating to https://example.com...
Fetched Cookies: [ ...cookie details... ]
Fetched Local Storage: { ...local storage details... }
Validating fetchA11yTreeForDialog...
Accessibility Tree for Dialog: { ...tree details... }
✅ fetchA11yTreeForDialog executed successfully.

Plugin Validation Completed.

Available Tasks

The plugin adds the following tasks for accessibility tree validation:

  1. Fetch Accessibility Tree for a Page Fetches the accessibility tree for a specified page.
cy.task('fetchA11yTreeForPage', {
  url: 'https://example.com',
  cookies: JSON.stringify(cookies), // Optional: Pass cookies if required
  localStorageData: JSON.stringify(window.localStorage) // Optional: Pass local storage data if needed
}).then((a11yTree) => {
  cy.wrap(a11yTree).as('a11yTree');
});
  1. Find Duplicates in A11y Tree Identifies duplicate element names in the accessibility tree.
cy.get('@a11yTree').then((a11yTree) => {
  cy.task('findDuplicates', a11yTree).then((result) => {
    cy.log(result);
  });
});
  1. Fetch A11y Tree for Dialogs Performs actions (e.g., clicking buttons) to open a dialog and fetches the accessibility tree.
cy.task('fetchA11yTreeForDialog', {
  url: 'https://example.com',
  cookies: JSON.stringify(cookies),
  localStorageData: JSON.stringify(window.localStorage),
  actions: [
    { action: 'click', selector: '#dialog-trigger' }
  ]
}).then((a11yTree) => {
  cy.wrap(a11yTree).as('a11yTree');
});
  1. Fetch A11y Tree for Menus Performs actions to navigate to a menu and fetches its accessibility tree.
cy.task('fetchA11yTreeForMenu', {
  url: 'https://example.com',
  cookies: JSON.stringify(cookies),
  localStorageData: JSON.stringify(window.localStorage),
  menuSelector: '#menu',
  actions: [
    { action: 'click', selector: '#menu-trigger' }
  ]
}).then((a11yTree) => {
  cy.wrap(a11yTree).as('a11yTree');
});

Contributing

We welcome contributions from the community! Please review our Contribution Guide and adhere to our Code of Conduct when participating.

If you encounter any issues or have feature requests, please report them in our Issues section.

Code of Conduct

This project adheres to a Code of Conduct. Please review it before participating.

Reporting Issues

Please check the Issues page for existing bugs and report new ones if needed.