Generating Reports With Python
Generating reporter-compatible JSON output and configuring reports with Axe DevTools for Web for Python
axe-devtools-api produces results in a format compatible with the Axe DevTools reporter.
Creating reporter-compatible JSON
Axe.analyze() returns a Results object. It can be converted to a reporter-compatible JSON string via Results.to_json().
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.
Once a ReportConfiguration object is in the desired state, it can be applied to a scan in two ways:
-
Apply it to a single scan by passing it to
Axe():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" -
Set it as the default for all scans that do not individually override it:
ReportConfiguration().test_suite_name("my suite").set_as_default() axe = Axe(driver) results = axe.analyze() assert results.name == "my suite"
To get the ReportConfiguration instance currently set as the default, call ReportConfiguration.get_default().
axe_devtools_api.Results
Returned by Axe.analyze(). Holds the axe-core findings and provides methods for inspecting and serializing them.
Properties
name
The test suite name. Set via ReportConfiguration.test_suite_name(). Defaults to "axe-run".
id
The scan identifier — a combination of the UI state value (set via ReportConfiguration.ui_state()) and a UUID, joined by a hyphen. Defaults to "check-<uuid>".
Methods
to_json()
Convert the results to a reporter-compatible JSON string.
is_axe_clean()
Return True if axe-core ran without error and found no violations.
is_errored()
Return True if axe-core encountered an error during the run.
violations_report()
Return a human-readable string summarizing any violations found. If axe-core errored, returns the error message instead.
axe_devtools_api.ReportConfiguration
Configures report metadata such as the test suite name and user agent information.
report_config = ReportConfiguration().test_suite_name("my suite").ui_state("login page")
axe = Axe(driver, report_configuration=report_config)ReportConfiguration()
Create a new ReportConfiguration with default values.
get_default()
Return the current default ReportConfiguration. Note that the default can be changed via set_as_default().
set_as_default()
Set this object as the default configuration for all Axe instances that do not specify their own.
reset_default()
Reset the default configuration to its initial state.
test_suite_name(name)
Set the test suite name. Used as the name field on the Results object.
name: The test suite name.
Returns this object for chaining.
ui_state(id)
Set the UI state for this set of tests. Used as the id field on the Results object.
id: A string identifier for the UI state (for example, "login-page" or "dark-mode").
Returns this object for chaining.
user_agent(ua)
Set the user agent string recorded in the report.
ua: The user agent string.
Returns this object for chaining.
test_machine(t_machine)
Set the name of the machine the tests were run on.
t_machine: An identifier for the machine.
Returns this object for chaining.
See Also
- Uploading JSON Accessibility Results to axe Reports describes how to upload your results to axe Reports.
- Obtaining an axe Reports API Key tells how to obtain an API key to begin using axe Reports.
- Creating and Filtering Reports shows how you can create accessibility reports in CSV, XML, or HTML from your JSON accessibility results. You can also filter your output by severity using this tool.
- How JSON Results are Stored on Disk describes the file naming conventions for JSON accessibility results.
- Using the CLI to Send Accessibility Results to axe Developer Hub shows how you can upload your
.jsonresults files to axe Developer Hub.
