Advanced API Usage with Ruby

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

Advanced Axe DevTools for Web Ruby usage including custom rules, reporting options, and the usage service

Not for use with personal data

This document discusses custom rules, reporting options, and the usage service with Ruby.

Custom Rules

You can specify custom axe rules in a JSON file.

note

If you do not yet have custom rules and wish to start with an empty custom ruleset, create an axe-ruleset.json file in the local directory with an empty JavaScript object, e.g.: {}.

Configure Custom Rules via an Environment Variable

The default configuration expects the custom rules file location to be config/axe-ruleset.json, relative to the current working directory.

You may override this location with the AXE_RULESET_PATH environment variable or manually via the Axe DevTools configuration.

Set the AXE_RULESET_PATH environment variable to change the location of your axe-ruleset.json:

AXE_RULESET_PATH=/path/to/your/axe-ruleset.json

Configuring Custom Rules via Axe DevTools Configuration

A configuration object is available for defining a custom rule location using the AxeDevTools.configure method if you do not wish to work with the AXE_RULESET_PATH environment variable.

All settings below are optional. You may omit the entire AxeDevTools.configure invocation to use original default values.

AxeDevTools.configure do |config|
  # path to json configuration providing custom rules and checks
  # set defaults to "config/axe-ruleset.json"
  config.axe_ruleset_path = "config/axe-ruleset.json"

  # Configure user pre-defined standard rule sets. Custom
  # rules override these rule sets. See https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md
  config.rule_set_id = '508'
end

Reporting Options

Configuring Reporting Options with Axe DevTools Configuration

The axe-devtools-* gems enable logging test results. Use the AxeDevTools.Configure invocation to set up a global configuration for reporting:

AxeDevTools.configure do |config|
  config.output_directory: 'my-results',
  config.test_machine: 'my-server',
  config.test_suite_name: 'Accessibility Tests For Application',
  config.user_agent: 'Headless Chrome'
end

expect(page).to be_audited_for_accessibility.logging_results({
  ui_state: 'Landing Page Load',
})

The reporting configuration can take the following properties:

Attribute Default Value Description
ui_state (Mandatory) Attribute to pass in options object.
output_directory (Optional) axe-reports Directory name, into which the reports are to be generated.
test_machine (Optional) Value to depict where the test is run. E.g., CircleCI, TesterMachine01
test_suite_name (Optional) axe-a11yCheck Suite name for the tests. E.g., My Module Test Suite
user_agent (Optional) null Pass a target user agent. E.g., chrome.
verbose (Optional) false flag to enable/disable detailed logging of stack trace and messages.

Also, note that all the above options for AxeDevTools.configure can be passed when configuring the WebDriver of choice. For example:

require 'axe-devtools-capybara'

AxeCapybara.configure do |config|
 config.axe_config_path = 'config/my-ruleset.json'
end

See Also

Usage Service

You can gain insight into Axe DevTools usage trends within your organization with the usage service.

By default, the usage service is enabled, and the tracking URL is https://usage.deque.com.

note

In the Ruby API, use the enableTracking configuration property described below to turn usage tracking off, rather than the AXE_TRACK_USAGE environment variable. If your usage events don't reach Deque, set the tracking URL explicitly with setTrackingUrl.

Configuring Usage Service Options with AxeDevTools Configuration

The axe-devtools-* gems allow for configuring the usage service via a global configuration:

AxeDevTools.configure do |config|
  config.setTrackingUrl: 'https://usage.deque.com',
end

The usage service specific configuration properties are:

Attribute Default Value Description
enableTracking true Option to enable usage tracking.
setTrackingUrl https://usage.deque.com Option to override tracking URL.

Also, note that all of the above options for AxeDevTools.configure can also be passed when configuring the WebDriver of choice. For example, for Capybara:

require 'axe-devtools-capybara'

AxeCapybara.configure do |config|
 config.enableTracking = false
end

Configuring Usage Service Options with Environment Variables

Additionally, usage service options can be configured via environment variables.

Name Type Can Override Description
AXE_DISTINCT_ID String A UUID identifier that remains the same for the logged-in user (unless it is regenerated). In Ruby, this variable is named DEQUE_DISTINCT_ID.
AXE_INCLUDE_TEST_RESULTS Boolean Set to true to include the full axe-core results in the testResults object of each event (default is false). Supported by the CLI and the Node.js APIs only.
AXE_METRICS_URL String The URL of the REST usage endpoint (default is https://usage.deque.com)
AXE_TRACK_USAGE Boolean Set to false to disable usage service reporting. Reporting is enabled by default.
AXE_APPLICATION String false The application that was used to check for accessibility errors
AXE_DEV_INSTANCE Boolean true Indicates whether this event is from a software developer's actions. Useful for marking and later removing events logged during development or testing.
AXE_DEPARTMENT String true The user's department within the organization
AXE_KEYCLOAK_ID String false The user's Keycloak ID
AXE_LOGGED_IN Boolean false Records whether the user is logged in to the application under test
AXE_ORGANIZATION String true The user's organization. To have your usage appear in Axe Reports, set this to your organization's ID (contact Deque to obtain it).
AXE_SESSION_ID String false A UUID identifying the user's session
AXE_USER_ID String false A specific user's identity such as an email address, name, or login ID. Axe Reports counts unique users from this value.
AXE_USER_JOB_ROLE String false The user's job role
AXE_USER_STATUS String false Status information you want to associate with the user