Riferimento API axe-devtools-unittest
Questo pacchetto fornisce asserzioni di supporto che estendono unittest per consentirne l'integrazione con axe DevTools.
Uso
Assicurati che la classe che si estende unittest.TestCase
si estenda anche AxeAssertions
class MyTests(unittest.TestCase, AxeAssertions):
...
Fornisce due asserzioni:
assertIsAxeClean(results)
Prende una serie di risultati axe e verifica che non vi siano violazioni. Genera un AssertionError
se c'è
Sono violazioni.
assertNoIncomplete(results)
Prende una serie di risultati axe e verifica che non vi siano controlli incompleti. I controlli incompleti sono Quelli che non sono stati né superati né falliti definitivamente. Sono contrassegnati in modo tale da indicare che una revisione manuale è richiesta una revisione.
Esempio
L'esempio seguente può essere avviato direttamente con Python presupponendo che axe-devtools-api, axe-devtools-selenium e axe-devtools-unittest siano installati.
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()