XCUITest类拆卸不会删除该应用程序.但是,如果它的实例被拆除,则可以工作.我究竟做错了什么? [英] XCUITest Class teardown isnt deleting the app. But works if its instance teardown. What am I doing wrong?

查看:109
本文介绍了XCUITest类拆卸不会删除该应用程序.但是,如果它的实例被拆除,则可以工作.我究竟做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个类别为试图删除该应用程序的拆解,但它无法识别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 = running foreground)中相同.另外-官方文档说.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类拆卸不会删除该应用程序.但是,如果它的实例被拆除,则可以工作.我究竟做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆