Generando informes con Python

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

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:

  1. Se puede aplicar a un solo escaneo vinculándolo a un único Axe objeto mediante Axe::__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"
  2. 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