-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
105 lines (75 loc) · 2.29 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict';
var express = require('express');
var favicon = require('serve-favicon');
var helmet = require('helmet')
var path = require('path');
var bodyParser = require('body-parser');
var pa11y = require('pa11y');
var automate = require('./automate/automate.json');
var app = express();
app.use(helmet());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
var router = express.Router();
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.use('/api', router);
var test = pa11y({
log: {
debug: console.log.bind(console),
error: console.error.bind(console),
info: console.log.bind(console)
},
beforeScript: function(page, options, next) {
function waitUntil(condition, retries, waitOver) {
page.evaluate(condition, function(error, result) {
if (result || retries < 1) {
// Once the changes have taken place continue with Pa11y testing
waitOver();
} else {
retries -= 1;
setTimeout(function() {
waitUntil(condition, retries, waitOver);
}, 2000);
}
});
}
// The script to manipulate the page must be run with page.evaluate to be run within the context of the page
page.evaluate(function() {
var user = document.querySelector('#username');
var password = document.querySelector('#password');
var submit = document.querySelector('#submit');
user.value = 'exampleUser';
password.value = 'password1234';
//submit.click();
}, function() {
// Use the waitUntil function to set the condition, number of retries and the callback
waitUntil(function() {
var elementExists = document.getElementById("signin_body");
if(elementExists){
return true;
}else{
return false;
}
//return window.location.href === 'http://example.com/myaccount';
}, 100, next);
});
}
});
router.route('/run').get(function(req, res) {
test.run('http://localhost:3000/apps/auth/signin/', function(error, result) {
if (error) {
//return console.error(error.message);
res.send(error.message);
}else{
res.send(result);
}
});
});
var server = app.listen(3000, function() {
console.log('api listening on', server.address().port);
});