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?
Welcome Mayuresh
I donāt have any idea except the one stated by you above for iOS device
have you implemented it (iOS idea)? Is it feasible?
No I havenāt implemented yet
Npā¦L try it outā¦Hope it works
I do it exactly the way you said⦠Swipe the control up and click on airplane mode
What are the swiping co-ordinates u pass?As it needs to be precise i guess
@Mitesh_Agrawal thanks man it worked in android real device
Welcome Jagadeesh
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.
In Java Swipe Up:
Dimensions d=driver.manage().window().getSize();
int width=d.getWidth();
int height=d.getHeight();
int w=(int) (.5width);
int h1=(int)(.2height);
driver.swipe(w,height,w,h1);
This worked for me.
@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)
Direct coordinates. You are outside your app so you wont be able to interact with objects my querying them in ios
User TouchActions to interact with anything outside your app
Ok cool :). Have used the same. Was thinking if there was an option in Appium to switch to the control center ,interact and come back to the app.This would make the code generic across all the devices.(As direct co-ordinates might change across devices)
Thanks man! This was really helpful. However, why are you multiplying the height and width by ā.5ā and ā.2ā ? Didnāt get hang of that.
He his finding the middle of the width so that the swipe is performed in the center of the phone horizontally and then for the real swipe movement he his going from full height until 20% of height.
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 );