forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaxe-phantom.js
51 lines (44 loc) · 1.14 KB
/
axe-phantom.js
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
46
47
48
49
50
51
/*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);
}
console.log('Testing, please wait...');
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({ include: ['#page'] }, 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 {
if (msg.violations.length) {
console.log(JSON.stringify(msg.violations, null, ' '));
} else {
console.log('No violations found!');
}
}
phantom.exit(msg.violations.length);
};
});