Simulate disable network
Device/Simulator – Android:
%x(adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings)
(For selecting Next element on the screen)
%x(adb shell input keyevent 20)
(For selecting previous element on the screen)
%x(adb shell input keyevent 19)
(For clicking on the selected element)
%x(adb shell input keyevent 23)
So you have to use select next or select previous key events and then you the click event to toggel the wifi.
Simulator – Android:
%x(adb shell svc wifi disable)
%x(adb shell svc wifi enable)
Device/Simulator – IOS:
First, setup a WiFi router that you can use for testing.
You can turn on Airplane mode on the phone, then turn WiFi back on. This will prevent the 3G connection from providing data access.
Launch your application. Now you can simply disconnect your WiFi router to simulate a loss of connectivity.
So the only option available is switch on airplane mode on phone and connect it to the wifi. Once you want to disconnect wifi switch off the wifi router itself. You can use any laptop to create the testing wifi access point.
Summarizing you have to connect your device in a wifi connection that you can control with System commands, the problem is that you will lost the connection of your machine.
%x[ifconfig Wi-Fi down]
%x[ifconfig en4 down]
%x[ifconfig Wi-Fi up]
%x[ifconfig en4 up]
But if you have an android phone you can easily create a portable wifi Hotspot which can be controlled using adb commands.