Skip to content

Instantly share code, notes, and snippets.

@sandipchitale
Created January 14, 2021 01:20
Show Gist options
  • Save sandipchitale/42d28d9f9e446f6ba41674cd1c3f83f0 to your computer and use it in GitHub Desktop.
Save sandipchitale/42d28d9f9e446f6ba41674cd1c3f83f0 to your computer and use it in GitHub Desktop.
axe+puppeteer
const util = require('util');
const puppeteer = require('puppeteer');
const axe = require('axe-core');
const urls = [
];
const results = [];
let axeResults;
puppeteer.launch({headless:false}).then(async browser => {
const promises = [];
const url = 'https://start.spring.io';
promises.push(browser.newPage().then(async page => {
await page.goto(`${url}`);
// add axe-core to the pages
await page.addScriptTag({
path: require.resolve('axe-core')
});
// run axe on the page
axeResults = await page.evaluate(async () => {
return await axe.run({
runOnly: {
type: 'tag',
values: ['wcag2a', 'wcag2aa']
}
});
});
// remove result data we don't need
delete axeResults.passes;
delete axeResults.inapplicable;
delete axeResults.incomplete;
// add results to the collection of axe results
results.push(axeResults);
await page.click('#explore-dependencies', {});
// run axe on the page again
axeResults = await page.evaluate(async () => {
return await axe.run({
runOnly: {
type: 'tag',
values: ['wcag2a', 'wcag2aa']
}
});
});
// remove result data we don't need
delete axeResults.passes;
delete axeResults.inapplicable;
delete axeResults.incomplete;
// add results to the collection of axe results
results.push(axeResults);
}))
await Promise.all(promises)
browser.close();
console.log(util.inspect(results, false, null, false))
});
{
"name": "axe",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"axe-core": "^4.1.1",
"puppeteer": "^5.5.0",
"util": "^0.12.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment