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 axe-devtools-ios package.
  6. For the Dependency Rule, select the exact version and enter the tag to retrieve.
  7. Click the Add Package button.
  8. You'll be prompted to select a target to add the framework to. For axeDevToolsXCUI, select the checkbox to the left, then select your UITest target. Click the Add Package button, and Xcode will begin fetching the assets.


Screenshot of Xcode's Swift Package Window to select a target where the framework will be added.

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

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

var axeDevTools: AxeDevTools?

Initialize the framework within the setUp or setUpWithError methods.

Connect with an 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)
    }
}