mozilla-services / axe-selenium-python

aXe Selenium Integration python package
https://pypi.python.org/pypi/axe-selenium-python/
Mozilla Public License 2.0
58 stars 50 forks source link

How to specify a11y standards? #173

Closed o-az closed 4 years ago

o-az commented 4 years ago

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"])
kimberlythegeek commented 4 years ago

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

o-az commented 4 years ago

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.

PyShaman commented 4 years ago

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