Created
January 14, 2019 18:34
-
-
Save bjankord/c8afaf345b4499ca3b1267063ce48562 to your computer and use it in GitHub Desktop.
axe-core + puppeteer set up
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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