XCUITestHelper 帮助您在 SwiftUI 中编写 UI 测试。它在 XCUIApplication、XCUIElement 和 XCUIElementQuery 上提供了一系列有用的扩展,使您的测试更具可读性且更易于维护。
dependencies: [
.package(url: "https://github.com/0xWDG/XCUITestHelper.git", branch: "main"),
],
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "XCUITestHelper", package: "XCUITestHelper"),
]),
]
https://github.com/0xWDG/XCUITestHelper
) 并点击 Next。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)
}
}
🦋 @0xWDG 🐘 mastodon.social/@0xWDG 🐦 @0xWDG 🧵 @0xWDG 🌐 wesleydegroot.nl 🤖 Discord
有兴趣了解更多关于 Swift 的信息吗?查看我的博客。