Skip to content

Instantly share code, notes, and snippets.

@bjankord
Created January 14, 2019 18:34
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjankord/c8afaf345b4499ca3b1267063ce48562 to your computer and use it in GitHub Desktop.
Save bjankord/c8afaf345b4499ca3b1267063ce48562 to your computer and use it in GitHub Desktop.
axe-core + puppeteer set up
const util = require('util');
const puppeteer = require('puppeteer');
const axe = require('axe-core');
const urls = [
'https://engineering.cerner.com/terra-ui/#/home/terra-ui/index',
'https://engineering.cerner.com/terra-ui/#/getting-started/terra-ui/what-is-terra',
];
const results = [];
let axeResults;
puppeteer.launch().then(async browser => {
const promises = [];
for (let i = 0; i < urls.length; i++) {
const url = urls[i];
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();
});
// 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, true))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment