Referencia API de 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
Not for use with personal data

Este paquete proporciona afirmaciones auxiliares que amplían unittest para permitir su integración con axe DevTools.

Uso

Asegúrese de que la clase que extiende unittest.TestCase también extienda AxeAssertions

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

Proporciona dos afirmaciones:

  • assertIsAxeClean(results)

Toma un conjunto de resultados de axe y se asegura de que no haya violaciones. Lanza un AssertionError si hay hay violaciones.

  • assertNoIncomplete(results)

Toma un conjunto de resultados de axe y se asegura de que no haya comprobaciones incompletas. Los controles incompletos son Aquellos que ni pasaron ni fallaron definitivamente. Están marcados de tal manera para indicar que se requiere una revisión manual. Se requiere revisión manual.

Ejemplo

El siguiente ejemplo se puede ejecutado directamente con Python asumiendo que axe-devtools-api, axe-devtools-selenium y axe-devtools-unittest están 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()