无法使用 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"] 是有效的。

enter image description here

有人使用 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...