Skip to content

Fixed #33620 -- Allowed running accessibility checks on selenium tests. #16372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

tushar5526
Copy link
Contributor

@tushar5526 tushar5526 commented Dec 8, 2022

Fixes ticket-33620

This is a PoC on how we could easily integrate aXe with existing selenium tests.

To test this, first, install axe-selenium-python. Add the run_axe decorator to the selenium tests that you need to run accessibility tests on.

This approach helps in the following:

  • Use existing selenium test cases, because generating selenium tests for each admin view, dropdowns, list and every path the user could take would be a great effort. We already have an exhaustive selenium test suite that we could use directly.
  • It would also support new tests also, so new features/ additions could also be tested for accessibility easily.

Things to improve this could be

  • axe is run towards the end of tests so it would be better if we run axe after each action or UI change.
  • A better report and discussion on metrics/visualization of reports. Maybe converts .json into a better representation.
  • Make it optional to run accessibility tests by providing flags in ./runtests.py command

This approach would work in GHA as well, we could either run tests headlessly or use xfvb to make a virtual frame buffer to mimic having a monitor in GHAs.

You can test the current single test on which I have added the decorator using the following.

 ./runtests.py --selenium=chrome admin_inlines.tests.SeleniumTests.test_add_stackeds          

Let me know your thoughts on how you are imagining this to work.

@carltongibson carltongibson requested a review from a team December 8, 2022 13:47
@carltongibson carltongibson changed the title Feat: Added a decorator that runs accessibility tests on existing selenium tests Fixed #33620 -- Allowed running accessibility checks on selenium tests. Dec 8, 2022
@carltongibson
Copy link
Member

axe is run towards the end of tests so it would be better if we run axe after each action or UI change.

Or at a specific point maybe? I have a view open — add run_axe() to run at that state — maybe passing the selenium instance if we need to... 🤔

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Thank you for your contribution 💪

As it's your first contribution be sure to check out the patch review checklist.

If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!

If you have any design or process questions then you can ask in the Django forum.

Welcome aboard ⛵️!

@smithdc1
Copy link
Member

smithdc1 commented Dec 8, 2022

axe-selenium-python Released: Nov 12, 2018

It doesn't look that well maintained. The latest version of Python in the test matrix is 3.6.

I'm not sure about having a dependency on this package as it is. 🤔

@tushar5526
Copy link
Contributor Author

Yes, nice catch. I went over to axe-selenium-python and the wrapper is fairly simple https://github.com/mozilla-services/axe-selenium-python/blob/master/axe_selenium_python/axe.py, maybe we can write our own logic to inject aXe into our admin page and then run it for results.

I also found out pa11y another accessibility test tool and it seems it has better support for generating better reports and also has an open-source dashboard to see results.

I will take a look into how we could use it and share some ideas soon.

@tushar5526
Copy link
Contributor Author

tushar5526 commented Dec 17, 2022

Hey @carltongibson @smithdc1 pa11y seems to be much better than using axe. pa11y can be called directly from CLI on URLs, we can use axe-core as a pa11y runner, it can output a decent formatted result, and have options to customize them even further. Apart from that, I see pa11y-dashboard as well to visualize results if needed.

After every UI change, writing a helper function that calls pa11y on the current selenium instance will not take much effort.

I highly favour using the existing admin tests for accessibility as compared to writing and maintaining accessibility tests.

One issue that I see with using pa11y as described above is redundancy in pa11y results because every time we would call pa11y, it would scan the whole page instead of only the new UI change.

pa11y has an option rootElement to only test a subset of DOM but this would require the use of "#" id tag to identify the elements that I doubt might be present on every UI piece of admin.

Other way than writing a whole accessibility testing suite is to iterate overall the .html files in the project and run pa11y over them to generate results. This might give us a lot of false positives like missing head tag or title tags due to .html file being in jinja template format.

Let me know your thoughts on the above points before I go ahead with something.

@felixxm
Copy link
Member

felixxm commented Dec 19, 2022

Closing per #16372 (comment). Please continue discussing possible solutions in the ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants