Generando informes con Python
axe-devtools-api produce resultados en un formato compatible con el generador de informes de Axe DevTools
Creación de JSON compatible con informes
Axe::analyze
devuelve un objeto con la forma correcta para su uso con el generador de informes Axe DevTools. Puede
Se puede convertir en una cadena JSON a través del Results::to_json
método.
A continuación se muestra un ejemplo en el que analizamos una página y guardamos los resultados en un archivo:
axe = Axe(driver)
results = axe.analyze()
with open("my_results.json", "w") as f:
f.write(results.to_json())
Configurando el informe
Los metadatos del informe se configuran a través de la ReportConfiguration
clase. Vea a continuación los métodos para
Configurar metadatos.
Una vez que un ReportConfiguration
objeto está en el estado deseado, se puede aplicar a un escaneo en dos
maneras:
-
Se puede aplicar a un solo escaneo vinculándolo a un único
Axe
objeto medianteAxe::__init__
report_config = ReportConfiguration().test_suite_name("my suite").ui_state("some state") axe = Axe(driver, report_configuration=report_config) results = axe.analyze() assert results.name == "my suite" assert results.id = "some state"
-
Se puede aplicar a todos los escaneos que no se anulan individualmente, configurando una instancia de
ReportConfiguration
como predeterminada.ReportConfiguration().test_suite_name("my suite").set_as_default() axe = Axe(driver) results = axe.analyze() assert results.name == "my suite"
Puede obtener la instancia que actualmente funciona como predeterminada llamando ReportConfiguration
ReportConfiguration.get_default
ReportConfiguration
API
@staticmethod
def get_default():
"""Gets the current default configuration. Note that the default can be changed.
Returns:
The current default
"""
def set_as_default(self):
"""Sets this object as the default"""
@staticmethod
def reset_default():
"""Resets the default to its initial state"""
def test_suite_name(self, name):
"""Sets the test suite name
Args:
name: The name
Returns:
This object for chaining
"""
def ui_state(self, id):
"""Specify the ui-state for this set of tests. Used as ID.
Args:
id: State id
Returns:
This object for chaining
"""
def user_agent(self, ua):
"""Set the user agent used when testing
Args:
ua: The user agent string
Returns:
This object for chaining
"""
def test_machine(self, t_machine):
"""Sets the machine the tests were run on
Args:
t_machine: Id for the machine
Returns:
This object for chaining
"""
Consulte también
- Cómo cargar resultados de accesibilidad JSON en axe Reports describe cómo cargar sus resultados en axe Reports.
- Cómo obtener una clave API de axe Reports indica cómo obtener una clave API para comenzar a utilizar axe Reports.
- Creación y filtrado de informes muestra cómo puede crear informes de accesibilidad en formato CSV, XML o HTML a partir de sus resultados de accesibilidad JSON. También puede filtrar su salida por severidad utilizando esta herramienta.
- Cómo se almacenan los resultados JSON en el disco describe las convenciones de nombres de archivos para los resultados de accesibilidad JSON.