Targeted Testing with XCTest

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

Add the framework into your UI tests

Not for use with personal data

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.

Automated Testing

XCTest is required to run axeDevToolsXCUI. Other UI testing frameworks are supported that utilize XCTest.

Setup for Testing

In any file used for accessibility testing, import the axeDevToolsXCUI framework.

import axeDevToolsXCUI

Create an object within your testing class to hold onto the axe DevTools instance:

var axe: AxeDevTools?

Initialize the framework within the setUp or setUpWithError methods.

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.

axe = try? AxeDevTools.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.

axe = try? AxeDevTools.startSession(apiKey: "<DEQUE_APIKEY>")

Setup Example

import axeDevToolsXCUI
import XCTest

class MyUITests: XCTestCase {
    var axe: AxeDevTools?
    var app = XCUIApplication()

    override func setUpWithError() throws {
        axe = try AxeDevTools.startSession(apiKey: "<DEQUE_APIKEY>",
            projectId: "<DEVHUB_PROJECT_ID>")
        // Include the projectId to post results to axe Developer Hub (recommended)
        app.launch()
    }
}

Connect with Offline License Key

Offline automation is available for the iOS 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.

import axeDevToolsXCUI_noauth
import XCTest

class MyUITests: XCTestCase {

    var axeDevTools: AxeDevTools?

    override func setUpWithError() throws {
        axeDevTools = AxeDevTools.loginWithLicenseKey("DEQUE_LICENSE_KEY")
    ...
}

What's Next?

Now that you have created a project and integrated the axeDevToolsXCUI framework, you are all set to scan your mobile app. Optionally, you can customize your configuration before you scan, if you want to name your scans, ignore certain results, create custom rules, or tag scans.