XCUITest应用程序快捷方式

时间:2017-01-24 09:51:50

标签: swift xctest xcode-ui-testing 3dtouch

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

我知道为了在模拟器中测试3D快捷键,你需要一个强力触控的触控板,但我想知道我是否可以编写测试我的快捷键的测试。

1 个答案:

答案 0 :(得分:0)

看起来是的!但是,您需要公开私有API。从Facebook's WebDriverAgent here导出XCUIElement标题。

或者,如果这是你唯一需要的东西,只需将它暴露出来:

@interface XCUIElement (Private)
    - (void)forcePress;
@end

然后通过转到跳板并获取图标元素see my answer here来强制按下您的图标。

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
        }
    }
 }

*我还没有测试过。