Génération de rapports avec 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 produit des résultats dans un format compatible avec le rapporteur Axe DevTools

Création de JSON compatible avec Reporter

Axe::analyze renvoie un objet dans la bonne forme pour une utilisation avec le rapporteur Axe DevTools. Il peut être converti en une chaîne JSON via la méthode Results::to_json .

Voici un exemple où nous analysons une page et enregistrons les résultats dans un fichier :

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

Configuration du rapport

Les métadonnées du rapport sont configurées via la class ReportConfiguration . Voir ci-dessous pour les méthodes à utiliser Configurer les métadonnées.

Une fois qu'un objet ReportConfiguration est dans l'état souhaité, il peut être appliqué à une analyse de deux manières. façons :

  1. Il peut être appliqué à une seule analyse en la liant à un seul objet via Axe 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. Elle peut être appliquée à toutes les analyses qui ne sont pas remplacées individuellement, en définissant une instance de ReportConfiguration comme valeur par défaut

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

Vous pouvez obtenir l'instance actuellement utilisée par défaut en appelant 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
    """

Voir aussi