問題描述
我有一個(gè)試圖刪除應(yīng)用程序的類拆解,但它無法識(shí)別 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()
}
}
這是在測(cè)試用例類拆解方法中調(diào)用的,如下所示
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)
}
這只是不會(huì)刪除應(yīng)用程序,但是如果我將類 func tearDown() 更改為 func tearDown() ,它會(huì)毫無問題地刪除應(yīng)用程序.不知道我錯(cuò)過了什么.有什么建議嗎?
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 中的一個(gè)錯(cuò)誤.當(dāng)聲明為 class
時(shí),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:
第一個(gè)選項(xiàng)是使用:
override func tearDown() {
XCUIApplication().terminate()
super.tearDown()
}
代替:
override class func tearDown() {…}
或者,以不同的方式終止應(yīng)用程序(按主頁按鈕,打開不同的應(yīng)用程序...).但是,我會(huì)使用第一種方式.
Or, terminate the app differently (press home button, open different app...). However, I would use the first way.
還可以考慮向 Apple 報(bào)告此問題,以便他們解決.
Also consider reporting this to Apple, so they can fix it.
這與應(yīng)用程序狀態(tài)(XCUIApplication().state.rawValue
)無關(guān),因?yàn)樗跍y(cè)試和 tearDown()
中是相同的(4 = 運(yùn)行前臺(tái)
).另外 - 官方文檔說 .terminate()
將終止應(yīng)用程序,該應(yīng)用程序與 Xcode 有一個(gè)調(diào)試會(huì)話,但調(diào)試會(huì)話在 tearDown()
中也處于活動(dòng)狀態(tài).所以這很可能是 Xcode 中的一個(gè)錯(cuò)誤.
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.
這篇關(guān)于XCUITest 類拆解不會(huì)刪除應(yīng)用程序.但是如果它的實(shí)例拆解就可以了.我究竟做錯(cuò)了什么?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!