axe-devtools-unittest API Reference
This package provides helper assertions which extend unittest to allow it to integrate with axe DevTools,.
Usage
Make sure the class that extends unittest.TestCase
also extends AxeAssertions
class MyTests(unittest.TestCase, AxeAssertions):
...
Provides two assertions:
assertIsAxeClean(results)
Takes a set of axe results and makes sure there are no violations. Throws an AssertionError
if there
are violations.
assertNoIncomplete(results)
Takes a set of axe results and makes sure there are no incomplete checks. Incomplete checks are those that neither difinitively passed nor failed. They are marked such so to signify that manual review is required.
Example
The following example can be ran 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()