Referência da API 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

Referência de API para o pacote axe-devtools-unittest que fornece asserções de acessibilidade para unittest

Not for use with personal data

Este pacote fornece asserções auxiliares que estendem unittest para integrar com Axe DevTools.

axe_devtools_unittest.AxeAssertions

Uma classe mixin que adiciona asserções de acessibilidade a unittest.TestCase. A classe de teste deve estender tanto unittest.TestCase quanto AxeAssertions.

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

assertIsAxeClean(results)

Afirma que o axe-core não encontrou violações.

results: O objeto de resultados retornado por Axe.analyze().

Levanta AssertionError se houver violações. A mensagem de erro inclui um relatório de violações.

assertNoIncomplete(results)

Afirma que o axe-core completou todas as verificações que tentou.

Verificações incompletas são aquelas que não passaram nem falharam definitivamente e requerem revisão manual.

results: O objeto de resultados retornado por Axe.analyze().

Levanta AssertionError se alguma verificação estiver incompleta.

assertInapplicable(results, *rules)

Afirma que as regras especificadas produziram resultados inaplicáveis.

results: O objeto de resultados retornado por Axe.analyze().

rules: Um ou mais IDs de regra para verificar o status de inaplicável.

Levanta AssertionError se alguma das regras especificadas não estiver nos resultados inaplicáveis.

Exemplo

O exemplo a seguir pode ser executado diretamente com Python, assumindo que axe-devtools-api, axe-devtools-selenium, e axe-devtools-unittest estejam instalados.

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()