Ignore Rules

Link to Ignore Rules copied to clipboard

Supported within:
XML Compose

You can choose to ignore specified rules while testing accessibility. We support ignoring a specific rule, ignoring rules by class name, and ignoring rules by accessibility identifier. While we feel that all rules are essential, these customizations will let you ignore views that have yet to be fixed and focus more on unknown or new issues.

important

In the below examples, axe refers to the AxeDevTools object initialized when logging in.

APIs Available

To ignore a specific rule or set of rules, update the configuration before testing takes place.

Ignore Rule(s)

The below code shows how to ignore a specific rule, EditTextName.

axe.ignoreRules(listOf("EditTextName"))

Ignore Some Rules by View ID

A set of rules that will be ignored for the assigned view ID.

axe.ignoreByViewId(
    R.id.failing_button,
    listOf(
        ActiveViewName::class.java
    )
)

Ignore All Rules by View ID

Ignores all rules for the provided view IDs.

axe.ignoreAllByViewId(listOf(R.id.your_view_id))

Ignore Some Rules by View

A set of rules that will be ignored for the provided views.

axe.ignoreByView(
    view,
    listOf(
        CheckBoxName::class.java
    )
)

Ignore All Rules by View

Ignores all rules for the provided views.

axe.ignoreAllByView(listOf(view))

Ignore Some Rules by Class Name

A set of rules that will be ignored for the provided class names.

axe.ignoreByClassName(
    TextView::class.java,
    listOf(
        ColorContrast::class.java
    )
)

Ignore All Rules by Class Name

Ignores all rules for the provided class names.

axe.ignoreAllByClassName(listOf(TextView::class.java))

Reset Ignored Rules for Automated Tests

Clear any currently ignored rules set by one of the above methods with the resetIgnoredRules API. Helpful for reseting the state between automated tests or runs, as needed.

XML Full Example

@Before  
fun setup() {
    axe.resetIgnoredRules()
}

@Test 
fun testButtonOnly() {
   axe.ignoreRules(listOf("ScreenTitle"))
   ...
}
 
@Test 
fun testScreenTitle() {
   ...
}

Compose Full Example

@Before  
fun setup() {
    axeCompose.resetIgnoredRules()
}

@Test 
fun testOthersWhileIgnoringComposeButtonName() {
   axeCompose.ignoreRules(listOf("ComposeButtonName"))
   ...
}
 
@Test 
fun testButtonName() {
   ...
}