Setup axeDevToolsXCUI.xcframework
Requires:
- Xcode 12.5.1 or newer
- iOS 13.4 or above
- Username and Password for the axe DevTools Mobile Dashboard
Download & Embed Framework
Using Swift Package Manager
Package URL: https://github.com/dequelabs/axe-devtools-ios.
- In Xcode select your main project to open project settings.
- In the settings pane, ensure the main project is selected and not a target.
- Select the
Package Dependencies
tab. - Select the plus icon to add a package dependency.
- Insert the package URL and select the version or branch to pull from.
Using Artifactory
View the instructions for using artifactory.
Embed Framework
- Drag the
axeDevToolsXCUI.xcframework
to your project's Frameworks folder. - Add it to your application's UI Test target.
- In project settings, select your application's UI Test target.
- Select the Build Phases tab.
- Add the framework to Copy Frameworks. (It should already be in Link Binary With Libraries).
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)
}
}