Targeted Testing with Espresso/UIAutomator
Initialize and configure the AxeDevTools library within your UI tests
When you want full control over when and where accessibility scans run in your tests, you should implement Targeted Testing. Follow the steps below for setting up the AxeDevTools library within your UI tests to check for accessibility issues. You will explicitly call the axe.scan() method at specific points in your code.
Note: This assumes you have already added the library to your project. For steps to install the Gradle plugin, please see Getting Started.
Automated Testing
Initialize the Library
In the test class init, connect to the library with one of the following:
Start a Testing Session
Generate an API key at axe.deque.com. To post results to axe Developer Hub, use startSession with the API Key and Project ID from Developer Hub.
private val axe = AxeDevTools()
init {
...
axe.startSession(apiKey = "<DEQUE_APIKEY>",
projectId = "<DEVHUB_PROJECT_ID>")
...
}If you only want to save results locally, you do not need to include the Project ID.
private val axe = AxeDevTools()
init {
...
axe.startSession(apiKey = "<DEQUE_APIKEY>")
...
}Connect with Offline License Key
Offline automation is available for the Android SDK, but will require an offline license key for authentication purposes. Please reach out to your Deque representative or contact support to coordinate the delivery of your license key. Then use the snippet below to connect to the axeDevTools library. See the FAQ for more information on using the Offline SDKs for optimized performance without network requests.
val axe = AxeDevTools()
init {
axe.setOfflineLicenseKey("OFFLINE_LICENSE_KEY")
}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?
Now that you have created a project and 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.
