XCUITest - How to disable Wi Fi while app is running?

旧时模样 提交于 2019-12-06 12:47:36

问题


I want to automate how ios App behave while running the XCUITest. When manually executing the test, I turn off the wi fi adapter. How do I do that using Xcode UI test?

thanks

p.s. I found that we can use below command to disable wi fi. But to do this I will need to send my app to background. I need to do this without sending current app to background.

let settingsApp = XCUIApplication(bundleIdentifier: "com.apple.Preferences")

settingsApp.launch()

settingsApp.tables.cells["Airplane Mode"].tap()

回答1:


You can re-activate your app afterwards with the new activate() method on XCUIApplication. It will resume your app without restarting it.

    let app = XCUIApplication()
    app.launch()

    let settingsApp = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
    settingsApp.launch()
    settingsApp.tables.cells["Airplane Mode"].tap()

    // Relaunch app without restarting it
    app.activate()


来源:https://stackoverflow.com/questions/46404535/xcuitest-how-to-disable-wi-fi-while-app-is-running

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!