Save Results Locally

Link to Save Results Locally copied to clipboard
Free Trial

Save results locally to utilize the axe DevTools Reporter CLI to build an executive report from a set of scans within your CI/CD pipeline.

A scan's result will be saved as a .json file. Saving results locally is only supported within automated testing.

For XML layouts, be sure to pass in the activity to scan. axe refers to the object you initialized in your test class setup.

axe.scan(activity)?.saveResultToLocalStorage("prefix")

For Compose layouts, axeCompose refers to the object you initialized in your test class setup.

axeCompose.scan()?.saveResultToLocalStorage("prefix")

Note: You can change the scan's name prior to saving the result.

Moving Result to the Build Folder

Add the below script to your app's build.gradle file, below the android block, and ensure it's not within another gradle task. Add your app package name in the packageName variable.

The script below will copy the result's generated from saving results locally on your emulator or device and move them into your build folder's report directory.

def reportsDirectory = "$buildDir/reports/androidTests/connected/axe"
def packageName = "your.app.package.name.here"
def fetchAxeReportsTask = task('fetchAxeReports', type: Exec, group: 'reporting') {
    executable "${android.getAdbExe().toString()}"
    args 'pull', '/storage/emulated/0/Android/data/' + packageName + '/files/AxeTestCases/.', reportsDirectory
def createAndroidFolderDirectoryTask = task('createAndroidFolderDirectoryTask', type: Exec, group: 'reporting') {
    executable "${android.getAdbExecutable().toString()}"
    args 'shell', 'mkdir', '-p', '/storage/emulated/0/Android/data/' + packageName + '/files/AxeTestCases'
}
def clearAndroidDirectoryTask = task('clearAndroidDirectoryTask', type: Exec, group: 'reporting') {
    executable "${android.getAdbExecutable().toString()}"
    args 'shell', 'rm', '-r', '/storage/emulated/0/Android/data/' + packageName + '/files/AxeTestCases'
}
def fetchAndroidFolderAxeReportsTask = task('fetchAndroidFolderAxeReportsTask', type: Exec, group: 'reporting') {
    executable "${android.getAdbExecutable().toString()}"
    args 'pull', '/storage/emulated/0/Android/data/' + packageName + '/files/AxeTestCases', reportsDirectory
    dependsOn {
        createAndroidFolderDirectoryTask
    }
    finalizedBy {
        clearAndroidDirectoryTask
    }
    doFirst {
        new File(reportsDirectory).mkdirs()
    }
}
def createDirectoryTask = task('createDirectoryTask', type: Exec, group: 'reporting') {
    executable "${android.getAdbExecutable().toString()}"
    args 'shell', 'mkdir', '-p', '/storage/emulated/0/Documents/AxeTestCases'
}
def clearDirectoryTask = task('clearDirectoryTask', type: Exec, group: 'reporting') {
    executable "${android.getAdbExecutable().toString()}"
    args 'shell', 'rm', '-r', '/storage/emulated/0/Documents/AxeTestCases'
    finalizedBy {
        fetchAndroidFolderAxeReportsTask
    }
}
def fetchAxeReportsTask = task('fetchAxeReportsTask', type: Exec, group: 'reporting') {
    executable "${android.getAdbExecutable().toString()}"
    args 'pull', '/storage/emulated/0/Documents/AxeTestCases', reportsDirectory
    dependsOn {
        createDirectoryTask
    }
    finalizedBy {
        clearDirectoryTask
    }
    doFirst {
        new File(reportsDirectory).mkdirs()
    }
}
tasks.configureEach { task ->
    if (task.name == 'connectedDebugAndroidTest') {
        task.finalizedBy {
            fetchAxeReportsTask
        }
    }
}