How do I log in / authenticate before testing in pa11y-ci?

1.5k Views Asked by At

I want to test pages as an authenticated user with pa11y-ci.

I am running pa11y-ci like this:

pa11y-ci --sitemap http://www.example.com/sitemap.xml --sitemap-find https --sitemap-replace http

I found some documentation on logging in with pa11y before running a test.

In my case, I'm using Drupal, so the login step looks like this:

    "actions": [
      'navigate to http://example.lndo.site/user/login'
        'set field #edit-name to pa11y',
        'set field #password to password',
        'click element #edit-submit',
        'wait for path to be /user'
    ]

However, I don't know how to add this "actions" to my .pa11yci configuration file, or how to call pa11y-ci and use this login step.

How can I log in before running a pa11y-ci test?

1

There are 1 best solutions below

0
On

I was able to log in like this in my .pa11yci:

First I do the anonymous pages (making sure to log out first), then I log in, and then I do my authenticated pages.

"urls": [
    {
      "url": "http://example.com/first-page",
        "actions": [
          "navigate to http://example.com/user/logout"
        ]
    },
    "REPLACE_BASE_URL/user/login",
    "REPLACE_BASE_URL/user/register",
    "REPLACE_BASE_URL/user/password",
    {
      "url": "http://example.lndo.site/auth-page-0",
        "actions": [
          "navigate to http://example.lndo.site/user/login",
          "set field #edit-name to [email protected]",
          "set field #edit-pass to password",
          "click element #edit-submit",
          "wait for element #user-page-unique-element to be visible"
       ]
     },
     "http://example.com/auth-page-1",
     "http://example.com/auth-page-2",
    ]
  }

The only problem with this approach is that I can't use the --sitemap command to test pages while authenticated.