Skip to content

Instantly share code, notes, and snippets.

@rowanmanning
Created March 16, 2017 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rowanmanning/bcd93ba305e561b75340596183847a07 to your computer and use it in GitHub Desktop.
Save rowanmanning/bcd93ba305e561b75340596183847a07 to your computer and use it in GitHub Desktop.
Pa11y Actions GitHub
// 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);
});
@bharatk89
Copy link

This code is not working and I'm getting an error no element matching the selector. Could some one please tell me how to identify element . need some help on Actions on pa11y. Thanks.

@vieirajluis
Copy link

vieirajluis commented Sep 18, 2020

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.

@R3dXIII
Copy link

R3dXIII commented Jul 6, 2022

Why is it requiring ../.. ?
var pa11y = require('../..');

@R3dXIII
Copy link

R3dXIII commented Jul 6, 2022

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.

@rowanmanning
Copy link
Author

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

@R3dXIII
Copy link

R3dXIII commented Jul 6, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment