我有一个类拆卸,它试图删除该应用程序,但它无法识别 app.terminate()。
class DeviceSettingsUtilities : UITestUtilities {
func removeApp(productName:String){
print("in teardown")
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
XCUIApplication().terminate() // this does nothing
XCUIApplication(bundleIdentifier: "com.xxx.xxxx").terminate()//this does nothing too, but this works when called as an instance teardown
sleep(5)
springboard.activate()
let icon = springboard.icons.matching(identifier: productName).firstMatch
// icon.exists is false when called as a class teardown
// icon.exists is true when called as an instance teardown
if icon.exists {
let iconFrame = icon.frame
let springboardFrame = springboard.frame
icon.press(forDuration:1.3)
springboard.coordinate(withNormalizedOffset: CGVector(dx: ((iconFrame.minX + 3) / springboardFrame.maxX), dy:((iconFrame.minY + 3) / springboardFrame.maxY))).tap()
sleep(5)
springboard.buttons["Delete"].firstMatch.tap()
sleep(5)
}
XCUIApplication().terminate()
}
}
这是在测试用例类拆卸方法中调用的,如下所示
override class func tearDown() {
super.tearDown()
let deviceSettings = DeviceSettingsUtilities()
deviceSettings.removeApp(productName: ProductName.rawValue)
}
这只是不会删除应用程序,但是如果我将 class func TeaDown() 更改为 func TeaDown() ,它会毫无问题地删除应用程序。不知道我错过了什么。有什么建议 ?
这似乎是最新 Xcode 10 中的一个错误。XCUIApplication.terminate()
似乎不起作用tearDown()
当声明为class
.
这可以通过两种方式解决:
第一个选项是使用:
override func tearDown() {
XCUIApplication().terminate()
super.tearDown()
}
代替:
override class func tearDown() {…}
或者,以不同方式终止应用程序(按主页按钮,打开不同的应用程序...)。不过,我会使用第一种方式。
还可以考虑向 Apple 报告此问题,以便他们修复。
编辑:这与应用程序状态无关(XCUIApplication().state.rawValue
),因为它在测试和中是相同的tearDown()
(4 = running foreground
)。另外 - 官方文件说.terminate()
将终止应用程序,该应用程序与 Xcode 有调试会话,但调试会话在以下位置处于活动状态tearDown()
以及。所以这很可能是 Xcode 中的一个错误。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)