axe-devtools-api Python API Reference
Provides an API with which to inject and configure axe.
Usage
Initialize with a browser adapter (such as an AxeDriver
from axe-devtools-selenium), and optionally a report
configuration object or a string of axe-core source code.
class Axe():
def __init__(self, page, report_configuration = None, axe_source = None):
...
The following methods are provided:
def analyze(self):
"""Run axe on the page
Returns:
The results from running axe-core on the page
Examples:
>>> report = Axe(page).analyze()
"""
def including(self, *selector):
"""Specify part of the page to run axe on.
Args:
selector: List of CSS selectors for elements
Returns:
This object for chaining
Examples:
>>> report = Axe(page).including(".sidebar-frame", ".some-class").analyze()
"""
def excluding(self, *selector):
"""Specify part of the page to exclude when runing axe.
Args:
selector: List of CSS selectors for elements
Returns:
This object for chaining
Examples:
>>> report = Axe(page).excluding(".iframe1",".third-party-ad").analyze()
"""
def with_rules(self, *rules):
"""Specify rules (by id) to use when running axe.
Only the specified rules are used.
List of rules available here: https://dequeuniversity.com/rules/axe/4.1
Args:
rules: List of ids of rules
Returns:
This object for chaining
Raises:
RuntimeError: If you try to call both `with_rules` and `with_tags` on the same object
Examples:
>>> report = Axe(page).with_rules("document-title", "label").analyze()
"""
def with_tags(self, *tags):
"""Specify rules (by tag) to use when running axe.
Only specified rules are used.
List of tags here: https://www.deque.com/axe/core-documentation/api-documentation/#axe-core-tags
Args:
tags: List of tags of rules
Returns:
This object for chaining
Raises:
RuntimeError: If you try to call both `with_rules` and `with_tags` on the same object
Examples:
>>> report = Axe(page).with_tags("best-practice", "wcag2a").analyze()
"""
def disabling_rules(self, *rules):
"""Disable some rules when running axe.
List of rules available here: https://dequeuniversity.com/rules/axe/4.1
Args:
rules: List of ids of rules
Returns:
This object for chaining
Examples:
>>> report = Axe(page).disabling_rules("html-has-lang", "label")
"""
def run_options(self, options):
"""Specify runOptions to pass to axe when calling axe.run
Documentation can be found here: https://www.deque.com/axe/core-documentation/api-documentation/#options-parameter
Args:
options: Object to pass
Returns:
This object for chaining
Examples:
>>> options = { "iframes": False }
>>> report = Axe(page).run_options(options).analyze()
"""
def configure(self, spec):
"""Configure axe. Done via axe.configure.
Args:
spec: Spec object to pass
Returns:
This object for chaining
Examples:
>>> import spec
>>> report = Axe(page).configure(spec).analyze()
"""
def without_iframe_sandboxes(self):
"""Remove the `sandbox` attribute from `iframe`s so that axe runs in them.
Returns:
This for chaining
Examples:
>>> report = Axe(page).without_iframe_sandboxes().analyze()
"""
def with_config_file(self, config_path):
"""Set where to find a config file.
Default path is `config/axe-ruleset.json` or `$AXE_RULESET_PATH`
Args:
config_path: Path to config file
Returns:
This object for chaining
Examples:
>>> report = Axe(page).with_config_file("path/to/file.json").analyze()
"""
def with_ruleset(self, ruleset_id, enable_best_practices = False):
"""Use a specific ruleset
Available rulesets: wcag2, wcag2.1, wcag2.2, wcag2aaa, wcag2.1aaa, wcag2.2aaa, 508, en301549, ttv5
Args:
ruleset_id: id of the ruleset to use
enable_best_practices: Whether or not to turn on rules tagged `best-practice`. Default off
Returns:
This object for chaining
Examples:
>>> report = Axe(page).with_ruleset("508").analyze()
"""
Usage Service
Gain insight into axe DevTools usage trends within your organization
By default the usage-service is disabled and the default url is https://usage.deque.com
.
Environment variables
This method allows users to change specific values of the usage service via environment variables
Environment Variable | Type |
---|---|
AXE_IS_LOGGED_IN | Boolean |
AXE_KEYCLOAK_ID | String |
AXE_USER_ID | String |
AXE_SESSION_ID | String |
AXE_USER_STATUS | String |
AXE_USER_JOB_ROLE | String |
AXE_DISTINCT_ID | String |
AXE_IS_DEV_INSTANCE | Boolean |
AXE_ORGANIZATION | String |
AXE_APPLICATION | String |
AXE_METRICS_URL | String |
AXE_TRACK_USAGE | Boolean |
def enable_tracking(self, state):
"""Opt in or out of sending data to usage service.
Args:
state: whether tracking is enabled
Returns:
This object for chaining
Examples:
>>> report = Axe(page).enable_tracking(True).analyze()
"""
self.analytics.enable_tracking(state)
return self
def set_tracking_url(self, url):
"""Set where usage metrics data are sent.
Args:
url: url where it will be sent
Returns:
This object for chaining
Examples:
>>> report = Axe(page).set_tracking_url("https://usage.deque.com").analyze()
"""
serlf.analytics.url(url)
return self
def set_distinct_id(self, id):
"""Set distinct id used when sending usage metrics.
Args:
id: distinct id to send
Returns:
This object for chaining
Examples:
>>> report = Axe(page).set_distinct_id("SOMEUUID").analyze()
"""
self.analytics.distinct_id(id)
return self
Example
The following is an example robot file.
*** Settings ***
Library axe_devtools_robot.AxeRobot
Suite Setup set log level DEBUG
*** Test Cases ***
Analyzes
Open Browser http://localhost:8000/example-page.html Chrome
Analyze
Audits
Open Browser http://localhost:8000/example-page.html Chrome
Audit For Accessibility
Uses Within
Open Browser http://localhost:8000/example-page.html Chrome
Within body
Analyze
Close browsers
Close All Browsers