Generando report 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 risultati in un formato compatibile con il reporter Axe DevTools

Creazione di JSON compatibili con il reporter

Axe::analyze restituisce un oggetto nella forma corretta da utilizzare con il reporter di Axe DevTools. Può Può essere convertito in una stringa JSON tramite il metodo Results::to_json .

Ecco un esempio in cui analizziamo una pagina e salviamo i risultati in un file:

axe = Axe(driver)
results = axe.analyze()
with open("my_results.json", "w") as f:
  f.write(results.to_json())

Configurazione del report

I metadati del report vengono configurati tramite la classe ReportConfiguration . Guarda qui sotto per i metodi per Configurare i metadati.

Quando un ReportConfiguration oggetto è nello stato desiderato, può essere applicato a una scansione in due modi:

  1. Può essere applicato a una singola scansione legandola a un singolo Axe oggetto tramite 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. Può essere applicato a tutte le scansioni che non sono state sovrascritte individualmente, impostando un'istanza di ReportConfiguration come predefinita

    ReportConfiguration().test_suite_name("my suite").set_as_default()
    
    axe = Axe(driver)
    results = axe.analyze()
    
    assert results.name == "my suite"

È possibile ottenere l'istanza che attualmente funge da predefinita chiamando 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
    """

Vedere anche