swift - XCUITest 应用程序快捷方式

标签 swift xctest xcode-ui-testing 3dtouch

是否有任何方法可以在 XCUITests 中测试 UIApplication 快捷方式?

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

最佳答案

看起来是的!不过,您需要公开私有(private) API。从 Facebook's WebDriverAgent here 中导出 XCUIElement header .

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

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

* 我还没有测试过。

关于swift - XCUITest 应用程序快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41824987/

相关文章:

swift - 使用 Swift 在 AppKit 中处理键盘事件

ios - XCTAssert NSSet 计数

swift - XCTest:检查是否未调用回调

ios - 在 iOS 应用程序的 UI 测试中禁用等待空闲状态

ios - 根据字符串数组中字符串的字符计数以一定时间间隔更改标签文本

ios - 如何从 Swift 中的数组中获取最新日期

ios - 运行时找不到方法

ios - 无法使用 XCTest 启动测试

xcode - SwiftUI:断言工作表可见

ios - Xcode UITest 中的页面控件