XCUITest - 如何在应用程序运行时禁用 Wi Fi? [英] XCUITest - How to disable Wi Fi while app is running?

查看:24
本文介绍了XCUITest - 如何在应用程序运行时禁用 Wi Fi?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动化 ios App 在运行 XCUITest 时的行为方式.手动执行测试时,我关闭了 wi fi 适配器.我如何使用 Xcode UI 测试来做到这一点?

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?

谢谢

附言我发现我们可以使用下面的命令来禁用 wi fi.但要做到这一点,我需要将我的应用程序发送到后台.我需要在不将当前应用发送到后台的情况下执行此操作.

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()

推荐答案

之后您可以使用 XCUIApplication 上的新 activate() 方法重新激活您的应用.它会在不重启的情况下恢复您的应用.

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()

这篇关于XCUITest - 如何在应用程序运行时禁用 Wi Fi?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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