問題描述
我有一個試圖刪除應用程序的類拆解,但它無法識別 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模板網!