Run a Scan
Ready, set, scan
Once you have imported and initialized the AxeDevTools
library, you're all set to scan. Run a scan from within your tests by calling axe.scan()
.
Sample scan
When you're ready to run a scan from within your tests, call axe.scan()
. In the example below, you will see how to use the ScanResultHandler
to upload results to the Mobile Dashboard, pass or fail tests, and save results locally for sharing with your team and reporting. This function is broken down further below the snippet.
private fun a11yScan() {
val scanResultHandler = axe.scan()
//1. Upload it to the dashboard
scanResultHandler?.uploadToDashboard()
//2. Use the results in your test suite
val result: AxeResult? = scanResultHandler?.getSerializedResult()
result?.axeRuleResults?.forEach { result ->
if(result.status == AxeStatus.PASS) {
...
}
else if(result.status == AxeStatus.FAIL) {
...
}
else if(result.status == AxeStatus.INCOMPLETE) {
...
}
}
//3. Save the result JSON to a local file for later use
scanResultHandler?.saveResultToLocalStorage("your_file_prefix")
}
Breakdown:
- From the result handler, call
uploadToDashboard()
to send the latest scan to the dashboard. The scan will be published from the authenticated account used in theinit
function. - From the result handler, call
getSerializedResult()
to access the library's results locally. For example, you may choose to fail the test when failures are found in the accessibility scan results. This will not upload your results to the server. Uploading your results is not required to download them locally. - From the result handler, call
saveResultToLocalStorage()
to save the results as JSON in a local file on your test device. To access the saved file, refer to the documentation for Saving Results Locally.
Deinitialize
Once the test has been completed, call tearDown()
on the AxeDevTools
object you have created to clear the state of previous tests. We recommend putting this in your testing file's @After
annotated function, but it can also be called within a test if needed.
@After
fun tearDown() {
axe.tearDown()
}
What's next?
Learn more about uploading scan results to the mobile dashboard and saving your results locally.