Switching WiFi's in On-Device-Integration-Tests

Hello Developer community,


In our company we are developing a communication framework to talk to devices whether they are locally available or remotely (via a proprietary cloud).

To test this functionality we currently have to run a lot of tests manually because they require joining different WiFi networks.


We really need to automate these tests because it takes a lot of manual effort to run them, but:

  • Running Unit Tests (even on a Phone by using a fake host app) i can't change the current WiFi.
    • NEHotspotHelper requires special permission from apple (via a request form)
    • NEHotspotConfigurationManager requires user interaction every single time that you try to switch the network
  • Starting in XCode 9 it is possible to open the Settings App and switch the connected WiFi programmatically, BUT...
    • this is only possible when running UI tests.
    • we develop a library, not an app
      • If i try to hide my tests inside a UI testing framework then i can't access the API of the library...
      • the library we develop is quite extensive so developing a UI element for every single API method is not feasible.


Is there really nothing that would allow switching WiFis in the context of a test?


I could even live with private APIs considering that their usage is part of the tests, NOT part of the framework that we want to ship.

First up, you should definitely file an enhancement request for a better solution to this problem. Please post your bug number, just for the record.

I could even live with private APIs …

Private APIs are not an appropriate topic of discussion here on DevForums but, even if they were, I doubt you’d find a solution on that path. There has been so much abuse of the Wi-Fi subsystem’s private APIs that they are now all closely restricted by the iOS sandbox.

I think your best option is to do this via a UI test. You wrote:

we develop a library, not an app

Right. The solution is to implement a simple wrapper app that you can target with UI testing.

the library we develop is quite extensive so developing a UI element for every single API method is not feasible.

Indeed. The idea here would be to implement test running infrastructure within your wrapper app. You don’t need a UI element per test, just a UI element to start the tests and another to indicate that they’re done.

This is clearly less than ideal — you miss out on all the nice features that Xcode provides for unit tests — which is why I started this response with a recommendation that you file an enhancement request. Still, I’m thinking that it should be enough to get you up and testing.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
How do you control the wifi/network state from a UITest? This thread suggests it's possible, but I'm looking at the API of XCUIDevice and XCUIApplication and I don't see anything.

What I want to do: I want to test the code in my app that displays in-app purchase prices. Specifically, this scenario:
  • Device has no internet connection. App starts up and tries to get in-app product info and fails.

  • Device connects to internet.

  • App detects this change, re-requests in-app product info, succeeds, and displays the prices.

So I need a way to turn the wifi and cellular networking off and on from within the UITest. Is it possible?
Switching WiFi's in On-Device-Integration-Tests
 
 
Q