axe-devtools-unittest API Reference
API reference for the axe-devtools-unittest package providing accessibility assertions for unittest
This package provides helper assertions which extend unittest to integrate with Axe DevTools.
axe_devtools_unittest.AxeAssertions
A mixin class that adds accessibility assertions to unittest.TestCase. The test class must extend both unittest.TestCase and AxeAssertions.
class MyTests(unittest.TestCase, AxeAssertions):
...assertIsAxeClean(results)
Assert that axe-core found no violations.
results: The results object returned by Axe.analyze().
Raises AssertionError if there are violations. The error message includes a violations report.
assertNoIncomplete(results)
Assert that axe-core completed all checks it attempted.
Incomplete checks are those that neither definitively passed nor failed and require manual review.
results: The results object returned by Axe.analyze().
Raises AssertionError if any checks are incomplete.
assertInapplicable(results, *rules)
Assert that the specified rules produced inapplicable results.
results: The results object returned by Axe.analyze().
rules: One or more rule IDs to check for inapplicable status.
Raises AssertionError if any of the specified rules are not in the inapplicable results.
Example
The following example can be run directly with Python, assuming axe-devtools-api, axe-devtools-selenium, and axe-devtools-unittest are installed.
import unittest
from os import path
from axe_devtools_api import Axe
from axe_devtools_selenium import AxeDriver
from axe_devtools_unittest import AxeAssertions
from selenium import webdriver
class TestAxe(unittest.TestCase, AxeAssertions):
def setUp(self):
self.page = webdriver.Chrome()
self.page.get("http://localhost:8000/example-page.html")
self.axe = Axe(AxeDriver(self.page))
def test_run_axe(self):
res = self.axe.analyze()
assert res.is_axe_clean(), res.violations_report()
def test_with_rules(self):
res = self.axe \
.with_rules("document-title", "label") \
.with_rules("region") \
.analyze()
self.assertNoIncomplete(res)
self.assertIsAxeClean(res)
def test_including_within_frame(self):
res = self.axe \
.including("#my-frame", "body") \
.analyze()
self.assertNoIncomplete(res)
self.assertIsAxeClean(res)
if __name__ == '__main__':
unittest.main()