如何解决无法使用 doubleTap() 进行简单的 UI 测试 (macOS)
我在 Mac App 项目中有这个简单的 ContentView
:
struct ContentView: View {
@State var isPresented: Bool = false
var body: some View {
HStack {
CustomView()
.frame(minWidth: 150,idealWidth: 150,maxWidth: 150,minHeight: 100,idealHeight: 100,maxHeight: 100,alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
.contentShape(Rectangle())
.accessibility(identifier: "touch1")
.onTapGesture(count: 2){
isPresented = true
}
}
.alert(isPresented: $isPresented) {
let alert = Alert(title: Text("Double Clicked"))
return alert
}
}
}
struct CustomView: View {
var body: some View {
vstack{
Image(systemName: "cursorarrow.click.2")
}
}
}
然后我想为它编写一个 UI 测试:
func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
XCTAssert(app.images["touch1"].isHittable)
app.images["touch1"].doubleTap()
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
XCTAssertTrue(app.alerts["Double Clicked"].waitForExistence(timeout: 1))
}
当我运行测试时,没有显示警报,但鼠标光标移到了我的按钮中间,这让我认为 app.images["touch1"]
是有效的。
有人使用 doubleTap()
吗?我如何在没有它的情况下对我的应用进行 UI 测试?
完整的日志如下:
2021-03-15 15:09:16.836806+0100 DoubleClickUITests-Runner[4333:80088] Running tests...
Test Suite 'Selected tests' started at 2021-03-15 15:09:17.019
Test Suite 'DoubleClickUITests.xctest' started at 2021-03-15 15:09:17.020
Test Suite 'DoubleClickUITests' started at 2021-03-15 15:09:17.021
Test Case '-[DoubleClickUITests.DoubleClickUITests testExample]' started.
t = 0.00s Start Test at 2021-03-15 15:09:17.025
t = 0.43s Set Up
2021-03-15 15:09:17.567336+0100 DoubleClickUITests-Runner[4333:80593] [Arbitration] starting DTServiceHub child handshake.0 (send: 0x5d03,receive: 0x5c3f)
2021-03-15 15:09:17.567677+0100 DoubleClickUITests-Runner[4333:80088] [Arbitration] attempting connection to singleton: 2568 with send port: 0x5e03
2021-03-15 15:09:17.568590+0100 DoubleClickUITests-Runner[4333:80088] [Arbitration] handshake SUCCESSFUL (child: 4335 -> singleton: 2568)
t = 0.55s Open org.tynsoe.DoubleClick
t = 0.72s Launch org.tynsoe.DoubleClick
t = 2.52s Wait for accessibility to load
t = 2.96s Setting up automation session
t = 2.99s Wait for org.tynsoe.DoubleClick to idle
t = 3.18s Find the "touch1" Image
t = 3.39s Double tap "touch1" Image
t = 3.39s Wait for org.tynsoe.DoubleClick to idle
t = 3.54s Find the "touch1" Image
t = 3.73s Synthesize event
t = 4.60s Wait for org.tynsoe.DoubleClick to idle
t = 4.76s Waiting 1.0s for "Double Clicked" Alert to exist
t = 5.76s Checking `Expect predicate `exists == 1` for object "Double Clicked" Alert`
t = 5.76s Checking existence of `"Double Clicked" Alert`
t = 5.87s Capturing element debug description
t = 5.87s Checking existence of `"Double Clicked" Alert`
/Users/yann/Desktop/DoubleClick/DoubleClickUITests/DoubleClickUITests.swift:36: error: -[DoubleClickUITests.DoubleClickUITests testExample] : XCTAssertTrue Failed
t = 6.14s Tear Down
Test Case '-[DoubleClickUITests.DoubleClickUITests testExample]' Failed (6.346 seconds).
Test Suite 'DoubleClickUITests' Failed at 2021-03-15 15:09:23.368.
Executed 1 test,with 1 failure (0 unexpected) in 6.346 (6.347) seconds
Test Suite 'DoubleClickUITests.xctest' Failed at 2021-03-15 15:09:23.369.
Executed 1 test,with 1 failure (0 unexpected) in 6.346 (6.348) seconds
Test Suite 'Selected tests' Failed at 2021-03-15 15:09:23.369.
Executed 1 test,with 1 failure (0 unexpected) in 6.346 (6.350) seconds
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。