3

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()
Desdenova
  • 5,278
  • 8
  • 35
  • 43
Flashmark
  • 109
  • 2
  • 9

1 Answers1

9

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()
Richard Venable
  • 7,842
  • 3
  • 41
  • 51
  • Additionally, if you want to know if the airplane mode is current enabled before you go to Settings, try `let isAirplaneMode = XCUIApplication(bundleIdentifier: "com.apple.springboard").statusBars.images["Airplane mode on"]` – Ting Yi Shih Jul 22 '21 at 05:43