pa11y / pa11y-ci

Pa11y CI is a CI-centric accessibility test runner, built using Pa11y
https://pa11y.org
GNU Lesser General Public License v3.0
525 stars 63 forks source link

Running Pa11y-ci with sitemap #65

Closed hollsk closed 2 years ago

hollsk commented 6 years ago

@paul-ks commented on Thu Aug 02 2018

Hi, I am running pa11y-ci with a sitemap like that: pa11y-ci --sitemap url of sitemap and I am getting the following message: The sitemap "url of sitemap" could not be loaded.

Also, how can I tell pa11y-ci to point to a sitemap on the filesystem instead of an url?

Thanks, Paul

hollsk commented 6 years ago

Hi @paul-ks - thanks for using Pa11y!

Can your sitemap be loaded in the browser? Pa11y CI can only fetch a sitemap from a URL, there's no support for local sitemaps at the moment. As a workaround, you could serve a sitemap from a local server and use that as the URL.

If you're testing an entire site locally, and not just trying to use a local sitemap file, another alternative might be to use the glob pattern in your CLI command, e.g.: pa11y-ci '**/*.html'

paul-ks commented 6 years ago

Thank you for your reply. Looks like using the glob pattern in the CLI command is working. However, is there a way to ignore some of the pages (.html pages) that have http-equiv="refresh" in the meta tag?

hollsk commented 6 years ago

Ah, ok - so your sitemap only includes a subset of pages you want to test against. You can write a shell script to ignore files based on their contents and then pass that to Pa11y, but IMO it'd be a lot easier to run the sitemap on a local server.

You can start up a simple http server with one CLI command if you're using OSX or Linux - cd into the directory where your sitemap is, and run python -m SimpleHTTPServer. You should be able to access your sitemap at http://localhost:8000/sitemap.xml once the server is running.

If you're on Windows, you'd need to install Python first - there's a setup guide here: https://developer.mozilla.org/en-US/docs/Learn/Common_questions/set_up_a_local_testing_server

paul-ks commented 6 years ago

Thank you again for your reply. So some pages, like I mentioned above, don't need to be verified (in other words, ignored). Those pages contain this meta tag: <meta http-equiv="refresh" content="0; url=..." />

So writing a script that looks for this http-equiv="refresh" and ignores this page could be a good option. On a side note, I am doing all this from script tasks in Bamboo which I believe is living on a Linux box. In the script shell, I have been using the glob pattern: pa11y-ci 'public/**/*.html' to test the pages and passing a config file to pa11y-ci, something like that: pa11y-ci '/public/**/*.html' --config .pa11yci.json

How can I pass the shell script that will ignore files to pa11y-ci in the command above?

hollsk commented 6 years ago

Using a shell script is a different way to solve your problem than globbing the local files. You would need to collect together the files you want to test against, by grepping inside them for the meta tag you want to exclude, and only selecting the files that don't have it. In your script you can then pipe the wanted pathnames (in a variable, maybe) to Pa11y CI.

I'm not a bash/shell expert, so you might find stackoverflow more helpful here 🙂

But again, it'd be much easier to serve the sitemap itself through a URL.

josebolos commented 6 years ago

Hi @paul-ks

As @hollsk mentioned, there are several ways of specifying what files or URLs pa11y-ci will test (sitemap URL, config file, or as CLI parameters). None of them filter based on what is inside the files, which is what you actually want. Your only solution here is to find a way to generate a list beforehand with all the files that you actually want to analyse with pa11y-ci.

You mention that you already have a sitemap.xml file. If this is the case, then the simplest way is to run an HTTP server using python, as described here: https://developer.mozilla.org/en-US/docs/Learn/Common_questions/set_up_a_local_testing_server#Running_a_simple_local_HTTP_server

I'm not familiar with Bamboo but, if it's anything like any other CI system that I know, it should have Python installed already. Once the server is running, then you'll be able to run pa11y-ci with the sitemap as a parameter.

If you don't have a working sitemap.xml, then you should be able to generate a list of the local files that you want to test using something like find and grep. Something along the lines of (untested):

grep -r -v 'http-equiv\s?=\s?\"refresh\"' * > my-files.txt

should get you more or less a list of the files that you want. You should be able then to run pa11y-ci with those files as arguments with something like:

pa11y-ci "$(< my-files.txt)"

Bear in mind I haven't tested this, so you may have to adapt those commands, based on your set up.

I hope that helps!

paul-ks commented 6 years ago

Hello, thank you both for your helpful replies. I adapted the logic mentioned above. I now have a file that contains the URLs we want. I am passing the file to pa11y-ci like that: pa11y-ci "$(< ${bamboo.build.working.directory}/included.txt)"

I am getting the following error:

/usr/lib/node_modules/pa11y-ci/node_modules/glob/sync.js:31 throw new Error('must provide pattern') ^   Error: must provide pattern at new GlobSync (/usr/lib/node_modules/pa11y-ci/node_modules/glob/sync.js:31:11) at Function.globSync [as sync] (/usr/lib/node_modules/pa11y-ci/node_modules/glob/sync.js:26:10) at /usr/lib/node_modules/pa11y-ci/node_modules/globby/index.js:78:35 at Array.reduce () at Function.module.exports.sync (/usr/lib/node_modules/pa11y-ci/node_modules/globby/index.js:77:19) at Object. (/usr/lib/node_modules/pa11y-ci/bin/pa11y-ci.js:58:21) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12)

Am I missing something?

josebolos commented 2 years ago

Hi @paul-ks

I'm hoping that you managed to fix this issue. Feel free to reopen if not.