XCUITest Example

Link to XCUITest Example copied to clipboard

Below is an example of getting started with XCUITests with both iOS frameworks:

axeDevToolsUIKit.xcframework

import axe_devtools_ios_sample_app
import axeDevToolsUIKit
import XCTest

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

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

        app.launch()
    }

    func testAccessibility() throws {
        let FAB_ID = "com.deque.axeDevTools.accessibilityFab"
        let fab = app.buttons[FAB_ID]

        // Tap the FAB to send the scan to the server
        fab.tap()

        // Once it returns, the result from the scan can be seen on the Dashboard.
        // The FAB's label has the key needed to retrieve the scan from the server.
        XCTAssert(fab.waitForExistence(timeout: 5))

        // Grab the result from the server
        guard let key = AxeDevToolsResultKey(fabTitle: fab.label), let result = try? axe?.getResult(key) else {
            XCTFail("Could not retrieve scan from the server.")
            return
        }

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

axeDevToolsXCUI.xcframework

import axeDevToolsXCUI
import XCTest

class AccessiblityXCUITest: XCTestCase {

    var axe: AxeDevTools?
    let app = XCUIApplication()

    override func setUpWithError() throws {
        continueAfterFailure = false
        axe = try AxeDevTools.login(withUsername: "<DEQUE_USERNAME>", andPassword: "<DEQUE_PASSWORD>")

        app.launch()        
    }

    func testMainScreen() throws {
        let result = try axe?.run(onElement: app)
        
        //Fail the build if accessibility issues are found.
        XCTAssertEqual(result?.failures.count, 0)
    }
}