I have a scenario in wherein i need to move real device to offline mode.
created
Jul '15
last reply
Sep '18
- 25
replies
- 8.3k
views
- 10
users
- 6
likes
- 5
links
I have a scenario in wherein i need to move real device to offline mode.
Use below script to achieve this:
NetworkConnectionSetting connection = new NetworkConnectionSetting(airplaneMode, wifi, data)
driver.setNetworkConnection(connection);//here driver type is Android driver
For Ex to switch device in airplane mode use below script:
NetworkConnectionSetting connection = new NetworkConnectionSetting(true, false, false)
driver.setNetworkConnection(connection);//here driver type is Android driver
Thanks @Mitesh_Agrawal.That works.
Also is there any way to do it for iOS. As i read the Some appium docs and it was mentioned that there is no such API available for iOS.
One way mentioned was "maybe with a screen swipe that pulls the control sheet up--you could click the airplane then. "
Any Thoughts?
@Mitesh_Agrawal thanks man it worked in android real device
I'm using ruby and I'm using
__swipe(0.5,0.999,0.5,0.2)
being by function:
def __swipe(start_x, start_y, end_x, end_y, duration = 1)
swipe(:start_x => start_x, :start_y => start_y, :end_x => end_x, :end_y => end_y, :duration => duration*1000)
end
In ruby we can use % so that translate into floats, while in java I think its only possible to pass int so it may not even be possible, not sure.
@Telmo_Cardoso Wanted to know how do you Click on Airplane Mode buttons(Basically interact with the Controls on control center) Are you using Direct co-ordinates(eg. (100,200)) or Giving any locators(eg.Xpath)
Dear All,
Let me do my best to help you all....
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).
}
Now mode got switched to Offline.
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 );
I have found this in the appium documentation for appium.
http://appium.io/docs/en/commands/device/network/toggle-airplane-mode/#appium-clients22
POST /session/:session_id/appium/device/toggle_airplane_mode
Is there any java example using this? How do we make the POST call on the driver?
Android:
iOS:
No standard way to do it, however one can emulate the normal user behaviour like it is described in https://appiumpro.com/editions/1513
Thank you @mykola-mokhnach. I will give this a try.
One clarification question. The comment states that:
“This option only works up to Android 6.”
Any idea this will work for Android 7 or above?