-
-
Save rowanmanning/bcd93ba305e561b75340596183847a07 to your computer and use it in GitHub Desktop.
// An example of executing some actions before Pa11y runs. | |
// This example logs in to GitHub and runs tests on the | |
// user dashboard page. Note: this won't work if you have | |
// two-factor auth enabled. | |
'use strict'; | |
var pa11y = require('../..'); | |
// Create a test instance with some default options | |
var test = pa11y({ | |
// Log what's happening to the console | |
log: { | |
debug: console.log.bind(console), | |
error: console.error.bind(console), | |
info: console.log.bind(console) | |
}, | |
// Run some actions before the tests | |
actions: [ | |
'click element .site-header-menu a[href=/login]', | |
'wait for url to be https://github.com/login', | |
'set field #login_field to <YOUR-GITHUB-USERNAME>', | |
'set field #password to <YOUR-GITHUB-PASSWORD>', | |
'click element input[type=submit]', | |
'wait for url to be https://github.com/' | |
] | |
}); | |
// Test http://example.com/ | |
test.run('https://github.com/', function(error, result) { | |
if (error) { | |
return console.error(error.message); | |
} | |
console.log(result); | |
}); |
Why is it requiring ../.. ?
var pa11y = require('../..');
I ran the code but I got "TypeError: test.run is not a function". I'm able to do something such as: "const response = await pa11y('https://test.com')" and it works fine.
This was written for a very old version of Pa11y and is no longer correct. How did you find it? I’d refer to the official Pa11y documentation to work out how to use actions
This was written for a very old version of Pa11y and is no longer correct. How did you find it? I’d refer to the official Pa11y documentation to work out how to use actions
I've been looking for documentation for pa11y for node but I can't find much.
I have actions running now, but I can't find a reference for what is possible with them. All examples use #username which would suggest an id="" attribute. What about class="" or name="" ? I've tried using .classname but that does not seem to work or leaving the # absent.
You have to call https://github.com/login:
test.run('https://github.com/login', function(error, result) {
if (error) {
return console.error(error.message);
}
console.log(result);
});
And from the actions, just like as following:
'wait for url to be https://github.com/login',
'set field #login_field to yourgitusername>',
'set field #password to yourgitpassword>',
'click element input[type=submit]',
'wait for url to be https://github.com/'
Then the result/test will be from https://github.com/
It did work for me. But you have to test an account that doesn't have two-factor auth enabled.