Save Scan Results Locally

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
Not for use with personal data

When you save scan results locally, you can use the JSON result to integrate accessibility metrics into different reporting tools. You can also create an HTML report to share via email or chat, to notify your team of the accessibility health of your test run.

Saving results locally is only supported within automated testing.

Save and Share Results

Use the following code to save test results on the actual physical device or emulator as a .json file. The "prefix" parameter will be the beginning of the file name you want to save the result as.

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

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

Generate an HTML Report and Summary

When using the Axe DevTools Gradle plugin, adding a call to generateHtmlReportAndSummary once per test class will generate a report locally on your device. This API call flushes any stored result files and looks at all the scans accumulated since the beginning of the test session (or since the last call to the method) to generate a report. When your test suite finishes, the Gradle plugin will automatically send reports to your project's build/reports directory.

note

If you prefer to save your results in a different directory, you can indicate this in the plugin configuration block of your build.gradle file.

axeDevTools {
    axeMobileApiKey = "AXE_API_KEY"
    axeProjectId = "DEVHUB_PROJECT_ID"
    axeAutoScanMode = false
    axeHtmlReportPath = 
        "User/Desktop/reports/AxeDevToolsMobileResults"
    axeAccountUrl = "https://axe.deque.com"
class SampleTest {
    
    @Before
    fun before() {
        axe.startScanSession(API_KEY, PROJECT_ID, OPTIONAL_CUSTOM_URL)
    }

    @Test
    fun test_desired_screen() {
        // navigateToScreen(DESIRED_SCREEN.title)
        val results = axe.scan()?.serializedResult?.axeRuleResults
        // assertForRule(results, "FocusableText", 12, 8, 1)
    }
    
    companion object {
        val axe: AxeDevTools = AxeDevTools()
        
        @JvmStatic
        @AfterClass
        fun afterClass() {
            axe.generateHtmlReportAndSummary("optional_name")
        }
    }
}

These reports will include screenshots and rule failures only. For more detailed reporting that will include the view hierarchy, rules that were marked as passed or incomplete, and details about rule failures, see the section below to learn how to utilize the Axe DevTools Reporter CLI.

Use Results for Detailed Reporting

Leverage scan results for reporting by moving the JSON files to your project's build folder. Then you can utilize the Axe DevTools Reporter CLI to build an HTML report from a set of scans. Alternatively, you can access the result files programmatically to integrate accessibility metrics with internal reporting tools.

Add the following 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 reports 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 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
        }
    }
}

Support on Cloud Testing Platforms

Saving a result locally will not work as expected on Cloud Testing Platforms. If you need support for Cloud Testing Platforms, please send a request to helpdesk@deque.com or at support.deque.com.