Make XCUIElement perform 3D touch for Automate UITest?

前端 未结 2 1878
轮回少年
轮回少年 2021-01-04 18:50

I\'m creating Automate UITest test case where I\'d like to test the scenario when users make 3D Touch interaction with an element, then shows them Peek and Pop view.

2条回答
  •  借酒劲吻你
    2021-01-04 19:17

    As of Xcode 10 there's no public API to achieve this. However you can use the -[XCUIElement forcePress] private API to simulate a full Peek and Pop interaction. Here's a simple Swift extension that exposes this functionality.

    extension XCUIElement {
        func _forcePress() {
            XCTAssert(exists) // Forces the app to idle before interacting
            perform(Selector(("forcePress")))
        }
    }
    

    Keep in mind that this is a private API and so may be subject to change/removal in future releases of Xcode. That is, your tests may start crashing when running with a different Xcode version.

提交回复
热议问题