Run a Scan

Link to Run a Scan copied to clipboard
Not for use with personal data

Ready, set, scan

Once you have imported and initialized the axeDevToolsXCUI framework, you're all set to scan. Run a scan anywhere in your UI tests by passing in any XCUIElement you'd like to test accessibility against. In the below example, we're passing in the XCUIApplication to test all of the views currently displayed in the app's flow.

func testAccessibility() throws {
    let result = try axe?.run(onElement: app)
}

Sample Scan

import axeDevToolsXCUI
import XCTest

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

    override func setUpWithError() throws {
        axe = try AxeDevTools.login(withAPIKey: "<DEQUE_APIKEY>")

        app.launch()
    }

    func testAccessibility() throws {
        guard let result = try axe?.run(onElement: app) else {
            XCTFail()
            return
        }

        // Send results to the dashboard in case of a failure.
        if result.failures.count > 0 {
            try axe?.postResult(result)
        }

        // Fail the build if failures were found
        XCTAssertEqual(result.failures.count, 0)
    }
}

Deinitialize

As a best practice, deinitialize the axe object using a tearDown function to clear the state of previous tests.

override func tearDown() {
    axe = nil
  }

What's next?

Learn more about uploading scan results to the mobile dashboard and saving your results locally.