django-commons/axe-selenium-python

How to specify a11y standards?

Closed this issue · 3 comments

o-az commented

How do I specify only wcag2aa for example? I don't want to test against all a11y violation standards. My current code:

from selenium import webdriver
from axe_selenium_python import Axe

def test():
	options = webdriver.ChromeOptions()
	options.add_argument("disable-infobars")
	options.add_argument("--disable-extensions")
	driver = \
		webdriver.Chrome(options=options, executable_path='/chromedriver')
	driver.get("https://example.com")
	axe = Axe(driver)
	axe.inject()
	results = axe.run()
	axe.write_results(results, 'a11y.json')

	driver.close()

	assert len(results["violations"]) == 0, axe.report(results["violations"])

Apologies that I haven’t responded yet—did you still need assistance?

o-az commented

I've been able to achieve what I needed, but thank you. Basically what I wanted is to provide a list of tags such as wcag2aa or section508 and have axe only writes the violations that have those tags to the json file. I converted both my tags and the aXe report tags to sets and compared:

# tags I provide
tags = [ 'wcag2aa', 'section508' ]

# loop through violations and only get ones that have 
# one or more of the tags I provided
report = [violation for violation in results['violations'] 
                 if bool(set(violation['tags']) & set(tags))]

axe.write_results(report, 'a11y.json')

I'm not sure if there's another way that's built into 'axe-selenium-python' but this ought to do for now.

Hi,
Is there any better way to get violations with provided tags? Or just this workaround?
Kind regards!