forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into isValidRole-abstracts
- Loading branch information
Showing
9 changed files
with
299 additions
and
155 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"env": { | ||
"es6": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 8 | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# axe-puppeteer-example | ||
|
||
This (very minimal) example demonstrates how to use `axe-core` with [Puppeteer](https://github.com/GoogleChrome/puppeteer). | ||
|
||
The example does not have feature pairty with [`axe-webdriverjs`](https://github.com/dequelabs/axe-webdriverjs), and does not run on `<iframe>`s. | ||
|
||
## To run the example | ||
|
||
* Ensure Node v8+ is installed and on `PATH` | ||
* Move to the `doc/examples/puppeteer` directory | ||
* Run `npm install` | ||
* Run `node axe-puppeteer.js http://www.deque.com` to run `axe-core` via Puppeteer against http://www.deque.com and output results to the terminal |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const puppeteer = require('puppeteer'); | ||
const axeCore = require('axe-core'); | ||
const { parse: parseURL } = require('url'); | ||
const assert = require('assert'); | ||
|
||
// Cheap URL validation | ||
const isValidURL = input => { | ||
const u = parseURL(input); | ||
return u.protocol && u.host; | ||
}; | ||
|
||
// node axe-puppeteer.js <url> | ||
const url = process.argv[2]; | ||
assert(isValidURL(url), 'Invalid URL'); | ||
|
||
const main = async url => { | ||
let browser; | ||
let results; | ||
try { | ||
// Setup Puppeteer | ||
browser = await puppeteer.launch(); | ||
|
||
// Get new page | ||
const page = await browser.newPage(); | ||
await page.goto(url); | ||
|
||
// Inject and run axe-core | ||
const handle = await page.evaluateHandle(` | ||
// Inject axe source code | ||
${axeCore.source} | ||
// Run axe | ||
axe.run() | ||
`); | ||
|
||
// Get the results from `axe.run()`. | ||
results = await handle.jsonValue(); | ||
// Destroy the handle & return axe results. | ||
await handle.dispose(); | ||
} catch (err) { | ||
// Ensure we close the puppeteer connection when possible | ||
if (browser) { | ||
await browser.close(); | ||
} | ||
|
||
// Re-throw | ||
throw err; | ||
} | ||
|
||
await browser.close(); | ||
return results; | ||
}; | ||
|
||
main(url) | ||
.then(results => { | ||
console.log(results); | ||
}) | ||
.catch(err => { | ||
console.error('Error running axe-core:', err.message); | ||
process.exit(1); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "axe-puppeteer", | ||
"version": "0.0.0", | ||
"private": true, | ||
"main": "axe-puppeteer.js", | ||
"dependencies": { | ||
"axe-core": "^3.0.3", | ||
"puppeteer": "^1.6.0" | ||
} | ||
} |
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
Oops, something went wrong.