How to turn off network in ios device?

i have a scenario for which i have to test network off scenarion . I am new in iOS automation can somebody help me in dealing with it???

1 Like

You can’t. network connection API isn’t currently supported on iOS
http://appium.io/slate/en/master/?java#adjusting-network-connection

1 Like

You have two ways, not sure if thats what you want:

A)
-) Disable Cellular connection for device and enable WiFi before tests starts
-) When you need the network off scenario, just do a swipe up from bottom to show bottom menu and do a click on wifi to turn it off (use coordinates %)
-) Click outside of menu to go back to your app

or

B) Use the bottom menu again and just enable/disable flight mode to your needs

Hope it helps

2 Likes

@Telmo_Cardoso:Thanks will try this up. Can we use it with simulator as well???

dunno, never used simulator for appium tests

@Neha_Rathore Did you get this to work? Let me know, this has become a blocker for me!

@Telmo_Cardoso Is there any way that we can run UIAutomator commands through appium? Because UIAutomator allows us to to toggle wi-fi.

@Pratyush: no i didn’t get any help

Dear All,

Let me do my best to help you all…

  1. Use driver.swipe functionality to bring the settings from bottom.
    { now if you wonder on how to find the co- ordinates , then
    A. Connect iPad to your device with Appium inspector opened.
    B. Swipe up the settings manually .
    C. Click on ‘Refresh’ button in Appium Inspector.
    4. You may notice “Quick Settings” preview on Appium inspector screen itself.
    5. Now choose “Precise Tap” from Appium Inspector and tap over ‘Wifi Icon’ (Green dot will be get marked) , this will also display the “StartX” and “StartY” value.
    6. Pass these value as an argument to the drive.tap (method).
    }

  2. Now mode got switched to Offline.

  3. To close the “Settings”, you don’t need to swipe. Instead you may follow the same steps and tap anywhere on page.

// hiding keyboard

int tap_startX= (int) 341.2;
int tap_startY = (int)451.3;
int tap_finger= 1;
int tap_duration=2;
driver.tap(tap_finger, tap_startX , tap_startY , tap_duration	);

//swipe up the settings to disable wifi
int swipe_startX= (int) 347.8;
int swipe_startY = (int)1021.4;
int swipe_endx= (int)363.6;
int swipe_endy= (int)800.6;
int swipe_duration =(int) 0.5;
driver.swipe(swipe_startX, swipe_startY, swipe_endx, swipe_endy, swipe_duration);

// disable wifi
int mode_startX= (int) 331.3;
int mode_startY = (int)907.3;
int mode_finger= 1;
int mode_duration=2;
driver.tap(mode_finger, mode_startX , mode_startY , mode_duration );
Enjoy !!!

1 Like

How do you access the menu from bottom. I get always a “point is not within the bounds of the screen exception”, if i tap more than y=600. But the size of the iPhone is 375x667.
It not possible for me to access the control center programmatically.
But strangeley i get notification center by swiping. I heard it is because the control center button is only accessible by going outside of the view.

Please Help me to fix this.

You cant access anything outside your app on real iOS device.

Please correct me anyone if i am wrong.

To make it work outside your app you need jailbreak your device.

I tried it also with activating the help button manually on the device to get it tapped with a function. It lightened up, but the test isn´t able to open to help button which would give me access to the control center. So i guess its not possible. :frowning:
How is the workflow to jailbreak the device and make it able to open the control center?

Hi All,

To switch the device to offline mode, I am trying to bring the Control Center from bottom of the screen by swiping. In the first swipe it shows an arrow which is to be swiped again to open the control center from the bottom. But before I could perform the second swipe, the arrow hides itself.

Anyone facing this issue? Any workaround for this one?

@Neha_Rathore , @Pratyush Did you guys resolved “How to put ios device offline programmatically”

I did not work on it as such. The only way I know of is by pulling the control center up and clicking on element by co-ordinates. Although, it is flaky.
Not sure if there is some native support in the new XCUITest framework

@Pratyush Many thanks for the reply, actually i need to test the offline behavior of the app, as i am storing some data when there is no network and when network comes back than the stored data will be sent to server through the web api.

Ideally you should test this on a unit or functional level. It is very easy to simulate such a scenario from within the code base itself.
Be it Swift or Objective-C, both provide you with such a functionality. Gets very flaky when you try doing this from the UI level.

@jitesh_upadhyay you can place feature request https://github.com/facebook/WebDriverAgent , they may include in coming release as this is very important feature for automation

@VikramVI many thanks for the reply, will follow the same.

@jitesh_upadhyay thanks.

Just in case somebody wondering; why I asked you to file issue under WDA , as https://github.com/appium/appium-xcuitest-driver uses WDA internally and appium uses XCUITest driver for iOS automation.

1 Like