我有一个试图删除应用程序的类拆解,但它无法识别 app.terminate().
I have a class teardown which is trying to remove the app, but it doesn't recognize 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()
}
}
这是在测试用例类拆解方法中调用的,如下所示
This is being called in the test case class teardown method as shown below
override class func tearDown() {
super.tearDown()
let deviceSettings = DeviceSettingsUtilities()
deviceSettings.removeApp(productName: ProductName.rawValue)
}
这只是不会删除应用程序,但是如果我将类 func tearDown() 更改为 func tearDown() ,它会毫无问题地删除应用程序.不知道我错过了什么.有什么建议吗?
This just doesnt delete the app, But if i change class func tearDown() to func tearDown() , it deletes the app with no problem. Not sure what i am missing. Any suggestions ?
这似乎是最新 Xcode 10 中的一个错误.当声明为 class
时,XCUIApplication.terminate()
似乎在 tearDown()
中不起作用.
This seems like a bug in latest Xcode 10.
XCUIApplication.terminate()
doesn't seem to work in tearDown()
when declared as class
.
这可以通过两种方式解决:
This can be solved in two ways:
第一个选项是使用:
override func tearDown() {
XCUIApplication().terminate()
super.tearDown()
}
代替:
override class func tearDown() {…}
或者,以不同的方式终止应用程序(按主页按钮,打开不同的应用程序...).但是,我会使用第一种方式.
Or, terminate the app differently (press home button, open different app...). However, I would use the first way.
还可以考虑向 Apple 报告此问题,以便他们解决.
Also consider reporting this to Apple, so they can fix it.
这与应用程序状态(XCUIApplication().state.rawValue
)无关,因为它在测试和 tearDown()
中是相同的(4 = 运行前台
).另外 - 官方文档说 .terminate()
将终止应用程序,该应用程序与 Xcode 有一个调试会话,但调试会话在 tearDown()
中也处于活动状态.所以这很可能是 Xcode 中的一个错误.
This has nothing to do with app state (XCUIApplication().state.rawValue
), since it is same in test and in tearDown()
(4 = running foreground
). Also - official documentation says that .terminate()
will terminate app, which has a debug session with Xcode, but the debug session is active in tearDown()
as well. So it is really probably a bug in Xcode.
这篇关于XCUITest 类拆解不会删除应用程序.但是如果它的实例拆解就可以了.我究竟做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!