Generando report con Python
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:
-
Può essere applicato a una singola scansione legandola a un singolo
Axeoggetto tramiteAxe::__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" -
Può essere applicato a tutte le scansioni che non sono state sovrascritte individualmente, impostando un'istanza di
ReportConfigurationcome predefinitaReportConfiguration().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
- Caricamento dei risultati di accessibilità JSON su axe Reports descrive come caricare i risultati su axe Reports.
- Ottenere una chiave API per axe Reports spiega come ottenere una chiave API per iniziare a utilizzare axe Reports.
- Creazione e filtraggio di report mostra come creare report di accessibilità in formato CSV, XML o HTML a partire dai risultati di accessibilità JSON. Utilizzando questo strumento puoi anche filtrare l'output in base alla gravità.
- Come vengono archiviati i risultati JSON su disco descrive le convenzioni di denominazione dei file per i risultati di accessibilità JSON.
