Skip to content

XCUITestHelper helps you writing UI tests within SwiftUI. It provides a set of useful extensions on XCUIApplication, XCUIElement and XCUIElementQuery to make your tests more readable and easier to maintain.

License

Notifications You must be signed in to change notification settings

0xWDG/XCUITestHelper

Repository files navigation

XCUITestHelper

XCUITestHelper helps you writing UI tests within SwiftUI. It provides a set of useful extensions on XCUIApplication, XCUIElement and XCUIElementQuery to make your tests more readable and easier to maintain.

Swift Package Manager License

Requirements

  • Swift 5.9+ (Xcode 15+)
  • iOS 13+, macOS 10.15+

Installation (Pakage.swift)

dependencies: [
    .package(url: "https://github.com/0xWDG/XCUITestHelper.git", branch: "main"),
],
targets: [
    .target(name: "MyTarget", dependencies: [
        .product(name: "XCUITestHelper", package: "XCUITestHelper"),
    ]),
]

Installation (Xcode)

  1. In Xcode, open your project and navigate to FileSwift PackagesAdd Package Dependency...
  2. Paste the repository URL (https://github.com/0xWDG/XCUITestHelper) and click Next.
  3. Make sure you add it to the UITest target!
  4. Click Finish.

Usage / Examples

import XCTest
import XCUITestHelper

final class MyAppUITests: XCTestCase {
    override func setUpWithError() throws {
        continueAfterFailure = false
    }

    func testExample() throws {
        // UI tests must launch the application that they test.
        let app = XCUIApplication()

        // * Set the app language to English.
        app.setLanguage(to: .english)
        // Do this before launching the app.
        app.launch()

        // * `Wait` for 1 second to continue
        app.wait(for: 1)

        // * Tap a `random` cell in a collection view.
        // Random works with any kind of element, not just buttons.
        app.collectionViews.buttons.random.tap()

        // * Go back to previous screen (NavigationView)
        app.navigateBack()

        // * Tap on the last button
        app.buttons.lastMatch.tap()

        // * Tap on the second button
        app.buttons[1].tap()

        // * Type something, and then clear it.
        let textfield = app.searchFields.firstMatch
        app.type(in: textfield, text: "a", action: .clear)
    }
}

Contact

We can get in touch via Mastodon, Twitter/X, Discord, Email, Website.

Interested learning more about Swift? Check out my blog.

About

XCUITestHelper helps you writing UI tests within SwiftUI. It provides a set of useful extensions on XCUIApplication, XCUIElement and XCUIElementQuery to make your tests more readable and easier to maintain.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages