【问题标题】:XCUITest application shortcutsXCUITest 应用程序快捷方式
【发布时间】:2017-06-09 01:30:42
【问题描述】:

有没有什么方法可以在 XCUITests 中测试 UIApplication 快捷方式?

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

【问题讨论】:

  • 您能找到解决方案吗?我正在尝试 Chase Holland 的建议,但它不起作用。我设法展示了应用程序快捷方式菜单,但只是偶尔出现一次,它并不能可靠地工作,但即使展示了它,我也无法点击任何快捷方式(即使直接在模拟器中使用鼠标也不行)。感谢您的更新!
  • @MiroslavKovac 遗憾的是没有

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


【解决方案1】:

看起来是的!不过,您需要公开一个私有 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
        }
    }
 }

* 我还没有测试过。

【讨论】:

  • XCUIElement 没有 forcePress 方法。
  • 您需要公开该方法,因为它是私有的。不过,自 Xcode 9.3 以来我还没有看过这个——他们可能已经从 Xcode 10.x 中完全删除了它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多