是否有任何方法可以在 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/