Setup axeDevToolsXCUI.xcframework

Link to Setup axeDevToolsXCUI.xcframework copied to clipboard

Requires:

Download & Embed Framework

Using Swift Package Manager

Package URL: https://github.com/dequelabs/axe-devtools-ios.

  1. In Xcode select your main project to open project settings.
  2. In the settings pane, ensure the main project is selected and not a target.
  3. Select the Package Dependencies tab.
  4. Select the plus icon to add a package dependency.
  5. Insert the package URL and select the version or branch to pull from.

Using Artifactory

View the instructions for using artifactory.

Embed Framework

  1. Drag the axeDevToolsXCUI.xcframework to your project's Frameworks folder.
  2. Add it to your application's UI Test target.
  3. In project settings, select your application's UI Test target.
  4. Select the Build Phases tab.
  5. Add the framework to Copy Frameworks. (It should already be in Link Binary With Libraries).


screenshot of Xcode highlighting steps to embed the framework.

Automated Testing

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

Setup for Testing

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

import axeDevToolsXCUI

Initialize the framework within the setUp or setUpWithError methods.

Connect with API key:

Generate an API key at axe.deque.com.

axe = try? AxeDevTools.login(withAPIKey: "<DEQUE_APIKEY>")

Connect with username and password:

axe = try? AxeDevTools.login(withUsername: "<DEQUE_USERNAME>", andPassword: "<DEQUE_PASSWORD>")

Connect to the desktop application:

To get started with the desktop application, be sure to reference Desktop Setup.

axe = try? AxeDevTools.setLocalConnection()
Enable local networking and arbitrary loads within your `Info.plist`


        <key>NSAppTransportSecurity</key>
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
            <key>NSAllowsLocalNetworking</key>
            <true/>
        </dict>

Setup Example

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()
    }
}

Capture a Scan

With the XCUI framework, you can 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)
}

Send Results to the Dashboard

With the result captured, you can now utilize various features available including asserting that there were no failures found. In this example we're going to send results to the server with the tag "Investigate" only when there were failures that occurred. This will make it easier for your team to share the results with the needed parties to investigate and resolve the found accessibility issues.

if result.failures.count > 0 {
    try axe?.postResult(result, withTags: ["Investigate"])
}    

Full Example

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, withTags: ["Investigate"])
        }

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