AxeRunOnly Class

Link to AxeRunOnly Class copied to clipboard

Control which accessibility rules are executed during axe Watcher testing

Free Trial
Not for use with personal data

The AxeRunOnly class allows you to limit which accessibility rules are executed during accessibility testing with axe Watcher. You can specify a set of rules or tags to run, excluding all others from the analysis. This provides a way to focus testing on specific accessibility requirements or concerns.

This class is used in conjunction with AxeRunOptions to customize the behavior of the axe-core analysis engine.

important

You cannot use both AxeRunOnly and accessibilityStandard (in ConfigurationOverrides) at the same time.

Constructor

AxeRunOnly()

Creates a new instance of AxeRunOnly with no settings configured.

AxeRunOnly runOnly = new AxeRunOnly();

Methods

setType(String type)

Sets the type of filtering to apply. Valid values are: "rule", "rules", "tag", or "tags".

Parameters:

  • type - String indicating the type of filter. Must be one of: "rule", "rules", "tag", or "tags".

Returns:

  • AxeRunOnly - The current instance for method chaining

Throws:

  • IllegalArgumentException - If an invalid type is provided

Example:

AxeRunOnly runOnly = new AxeRunOnly();
runOnly.setType("tag");

setValues(List<String> values)

Sets the specific rule IDs or tag names to include in the analysis, based on the type that was set.

Parameters:

  • values - List of rule IDs or tag names to include in the analysis

Returns:

  • AxeRunOnly - The current instance for method chaining

Example:

AxeRunOnly runOnly = new AxeRunOnly();
runOnly.setType("tag");
runOnly.setValues(Arrays.asList("wcag2a", "wcag2aa"));

getType()

Gets the currently configured filter type.

Returns:

  • String - The current filter type ("rule", "rules", "tag", or "tags")

Example:

AxeRunOnly runOnly = new AxeRunOnly();
runOnly.setType("tag");
String type = runOnly.getType(); // Returns "tag"

getValues()

Gets the list of rule IDs or tag names that are configured for inclusion.

Returns:

  • List<String> - The list of included rule IDs or tag names

Example:

AxeRunOnly runOnly = new AxeRunOnly();
runOnly.setValues(Arrays.asList("wcag2a", "wcag2aa"));
List<String> values = runOnly.getValues(); // Returns the list of values

toJson()

Serializes the AxeRunOnly instance to a JSON string.

Returns:

  • String - A JSON string representation of the configuration

Example:

AxeRunOnly runOnly = new AxeRunOnly()
    .setType("tag")
    .setValues(Arrays.asList("wcag2a", "wcag2aa"));
String json = runOnly.toJson();
// Returns: {"type":"tag","values":["wcag2a","wcag2aa"]}

Common Tag Values

Here are some common tag values you can use with the AxeRunOnly class:

  • wcag2a: WCAG 2.0 Level A requirements
  • wcag2aa: WCAG 2.0 Level AA requirements
  • wcag2aaa: WCAG 2.0 Level AAA requirements
  • wcag21a: WCAG 2.1 Level A requirements
  • wcag21aa: WCAG 2.1 Level AA requirements
  • wcag21aaa: WCAG 2.1 Level AAA requirements
  • wcag22a: WCAG 2.2 Level A requirements
  • wcag22aa: WCAG 2.2 Level AA requirements
  • wcag22aaa: WCAG 2.2 Level AAA requirements
  • best-practice: Best practice rules that aren't part of a specific standard
  • experimental: Experimental rules that are still being developed

See Axe-core Tags for more axe-core tags.

See Also