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
519 stars 63 forks source link

Allow pa11y-ci to access authenticated areas #96

Closed Jamesking56 closed 2 years ago

Jamesking56 commented 4 years ago

It would be nice if we could give pa11y some login details for certain pages so that pa11y could login and accessibility test pages that require authentication

ptmkenny commented 3 years ago

pa11y can already do this, so there should be a way to do something similar in pa11y-ci. I'm searching for a solution now.

greggles commented 2 years ago

Here's a stackoverflow conversation about how to achieve it: that uses the "actions" in .pa11y-ci to authenticate:

"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 pa11y@example.com",
          "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",
    ]
  }

You likely need to tweak the useIncognitoBrowserContext setting as well. I have not tried this solution.

josebolos commented 2 years ago

This should be certainly possible using actions. Please create a new issue with the specific example config that is not working. Thank you!

kussmaul commented 1 year ago

This is (an excerpt of) what works for me, with useIncognitoBrowserContext false (no quotes).

"defaults" : {
  "useIncognitoBrowserContext": false
},

"urls" : [
  {
    "__NOTE"  : "this should always be FIRST (if browser context is preserved)",
    "url"     : "http://localhost:4200/login",
    "actions" : [
      "navigate to http://localhost:4200/login",
      "wait for element #login to be visible",
      "screen capture .pa11y/login0.png",
      "set field #username to Pa11y Author",
      "set field #password to Pa11y Password",
      "click element #login",
      "wait for element #appMenu to be visible",
      "screen capture .pa11y/login1.png"
    ]
  },

  {
    "url"     : "http://localhost:4200/activity-list",
    "actions" : [
      "navigate to http://localhost:4200/activity-list",
      "screen capture .pa11y/activity-list0.png",
      "wait for path to be /activity-list",
      "screen capture .pa11y/activity-list1.png"
    ]
  },
  ...
]