Riferimento API di axe-devtools-unittest

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard

Riferimento API per il pacchetto axe-devtools-unittest che fornisce asserzioni di accessibilità per unittest

Not for use with personal data

Questo pacchetto fornisce asserzioni di supporto che estendono unittest per integrarsi con Axe DevTools.

axe_devtools_unittest.AxeAssertions

Una classe mixin che aggiunge asserzioni di accessibilità a unittest.TestCase. La classe del test deve estendere sia unittest.TestCase che AxeAssertions.

class MyTests(unittest.TestCase, AxeAssertions):
    ...

assertIsAxeClean(results)

Verifica che axe-core non abbia trovato violazioni.

results: L'oggetto dei risultati restituito da Axe.analyze().

Solleva AssertionError se ci sono violazioni. Il messaggio di errore include un report delle violazioni.

assertNoIncomplete(results)

Verifica che axe-core abbia completato tutti i controlli tentati.

I controlli incompleti sono quelli che non hanno né superato né fallito definitivamente e richiedono una revisione manuale.

results: L'oggetto dei risultati restituito da Axe.analyze().

Solleva AssertionError se ci sono controlli incompleti.

assertInapplicable(results, *rules)

Verifica che le regole specificate abbiano prodotto risultati non applicabili.

results: L'oggetto dei risultati restituito da Axe.analyze().

rules: Uno o più ID di regole da verificare per lo stato non applicabile.

Solleva AssertionError se una delle regole specificate non è nei risultati non applicabili.

Esempio

Il seguente esempio può essere eseguito direttamente con Python, a condizione 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()