XCUITest 应用程序快捷方式

Ale*_*tiş 5 xctest swift xcode-ui-testing 3dtouch

有没有办法在 XCUITests 中测试 UIApplication 快捷方式?

我知道为了在模拟器中测试 3d 快捷方式,您需要一个带有强制触摸功能的触控板,但我想知道是否可以编写测试我的快捷方式的测试。

Cha*_*and 0

看起来是的!不过,您需要公开一个私有 API。XCUIElementFacebook 的 WebDriverAgent导出标头(此处) 。

或者,如果这是您唯一需要的东西,只需将其公开即可:

@interface XCUIElement (Private)
    - (void)forcePress;
@end
Run Code Online (Sandbox Code Playgroud)

然后通过转到跳板并获取图标元素来强制按下您的图标,请参阅我的答案

class Springboard {
    // this is another private method you'll need to expose (see linked other answer)
    static let springboard = XCUIApplication(privateWithPath: nil, bundleID: "com.apple.springboard")


    /// Open the 3d touch menu
    class func open3dTouchMenu() {
        XCUIApplication().terminate() // this may or may not be necessary depending on your desired function / app state

        // Resolve the query for the springboard rather than launching it
        springboard.resolve()

        // Force delete the app from the springboard
        let icon = springboard.icons["MyAppName"]
        if icon.exists {
            icon.forcePress()
            // do something with the menu that comes up
        }
    }
 }
Run Code Online (Sandbox Code Playgroud)

* 我还没有测试过这个。