Attributing Violations to Tests

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

See which test triggered each accessibility violation in Axe Developer Hub

Not for use with personal data

When a scan finds an accessibility violation, Axe Developer Hub can show you which test was running at the time. This makes it easy to trace a violation back to its source: open the test file, navigate to the test location, and fix the problem.

Automatic Collection (JavaScript and TypeScript)

The following integrations collect test context automatically. No configuration is required:

  • Playwright Test: the test file path and title path are captured from TestInfo at the start of each test.
  • Cypress: the test file path and title path are captured from Cypress.spec.relative and Cypress.currentTest.titlePath.
  • WebdriverIO Testrunner: the test file path and title path are captured from the test runner's describe/it title chain.

If you are using one of these integrations with a test runner, violations are attributed to tests automatically.

Manual Collection (Java)

Java tests do not have automatic access to the test runner, so you set the test context manually. Both AxeWatcherController (Selenium) and AxeWatcherPlaywrightController (Playwright) provide a setTestContext() method.

Call setTestContext() at the start of each test, typically in a @BeforeEach hook. Pass the test file path and a list representing the test location (class name and method name):

@BeforeEach
public void setUp() {
    driver.axeWatcher().setTestContext(
        "src/test/java/com/acme/LoginTest.java",
        java.util.Arrays.asList("LoginTest", "rejects bad password")
    );
}

Using JUnit TestInfo

If your test framework provides test identity at runtime, you can pass it directly:

@BeforeEach
public void setUp(TestInfo testInfo) {
    driver.axeWatcher().setTestContext(
        testInfo.getTestClass().map(Class::getName).orElse(null)
            .replace('.', '/') + ".java",
        java.util.Arrays.asList(
            testInfo.getTestClass().map(Class::getSimpleName).orElse(null),
            testInfo.getTestMethod().map(Method::getName).orElse(null)
        )
    );
}

Clearing the Context

Pass null, null to clear the attribution between tests:

driver.axeWatcher().setTestContext(null, null);