Generating Reports With Python

Link to Generating Reports With Python copied to clipboard

axe-devtools-api produces results in a format compatible with the Axe DevTools reporter

Creating reporter-compatible JSON

Axe::analyze returns an object in the right shape for use with the Axe DevTools reporter. It can be converted to a JSON string via the Results::to_json method.

Here is an example where we analyze a page and save the results to a file:

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

Configuring the report

Report metadata is configured via the ReportConfiguration class. See below for methods to configure metatdata.

Once a ReportConfiguration object is in the desired state, it can be applied to a scan in two ways:

  1. It can be applied to a single scan by tying it to a single Axe object via 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. It can be applied to all scans that are not individually overridden, by setting an instance of ReportConfiguration as the default

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

You can get the ReportConfiguration instance currently serving as the default by calling 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
    """

See Also