Requires:
- Xcode 15 or newer
- iOS 16 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
axe-devtools-ios
package. - For the
Dependency Rule
, select the exact version and enter the tag to retrieve. - Click the
Add Package
button. - 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 theAdd Package
button, and Xcode will begin fetching the assets.
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
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>")
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)
}
}