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 5.9+ (Xcode 15+)
- iOS 13+, macOS 10.15+
dependencies: [
.package(url: "https://github.com/0xWDG/XCUITestHelper.git", branch: "main"),
],
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "XCUITestHelper", package: "XCUITestHelper"),
]),
]
- In Xcode, open your project and navigate to File → Swift Packages → Add Package Dependency...
- Paste the repository URL (
https://github.com/0xWDG/XCUITestHelper
) and click Next. - Make sure you add it to the UITest target!
- Click Finish.
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)
}
}
We can get in touch via Mastodon, Twitter/X, Discord, Email, Website.
Interested learning more about Swift? Check out my blog.