Setup for Automated Testing

Link to Setup for Automated Testing copied to clipboard

Initialize and configure the AxeDevTools library within your UI tests

Not for use with personal data

This page highlights the steps for setting up the AxeDevTools library within your UI tests to check for accessibility issues. This assumes you have already added the library to your project. For steps to pull in the library, please see Getting Started.

Automated Testing

Initialize the Library

In the test class init, connect to the library with one of the following:

Connect with API key:

Generate an API key at axe.deque.com.

private val axe = AxeDevTools()

init {
  ...
  axe.loginWithApiKey("DEQUE_API_KEY")
  ...
}

Connect with username and password:

private val axe = AxeDevTools()

init {
    ...
    axe.loginWithUsername(
        "DEQUE_USERNAME",
        "DEQUE_PASSWORD"
    )
    ...
}

Set the Instrumentation Registry

This is the piece that allows axe DevTools for Android to connect to the view hierarchy. This can be set before your tests run in the @Before fun setup() block.

private val axe = AxeDevTools()

@Before
fun setup()  {
  axe.setInstrumentation(InstrumentationRegistry.getInstrumentation())
}

What's Next?

After you have imported the AxeDevTools library, you are all set to scan your mobile app. Optionally, you can customize your configuration before you scan, using our APIs to name your scans, ignore certain results, create custom rules, tag scans and more.