forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaxe-phantom.js
More file actions
45 lines (39 loc) · 987 Bytes
/
axe-phantom.js
File metadata and controls
45 lines (39 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*global window, phantom */
var PATH_TO_AXE = 'node_modules/axe-core/axe.min.js';
var args = require('system').args;
var fs = require('fs');
var page = require('webpage').create();
if (args.length < 2) {
console.log('axe-phantomjs.js accepts 1 argument, the URL to test');
phantom.exit(1);
}
page.open(args[1], function (status) {
// Check for page load success
if (status !== 'success') {
console.log('Unable to access network');
return;
}
page.injectJs(PATH_TO_AXE);
page.framesName.forEach(function (name) {
page.switchToFrame(name);
page.injectJs(PATH_TO_AXE);
});
page.switchToMainFrame();
page.evaluateAsync(function () {
/*global axe */
axe.run(function (err, results) {
if (err) {
throw err;
}
window.callPhantom(results);
});
});
page.onCallback = function (msg) {
if (args[2]) {
fs.write(args[2], JSON.stringify(msg, null, ' '), 'w');
} else {
console.log(JSON.stringify(msg, null, ' '));
}
phantom.exit();
};
});