Issue
I am currently working on an Espresso test suite that covers offline functionality. In order for me to implement these tests, I need to create a method that I can call to toggle on/off network connectivity. So far, I have been able to toggle WiFi, but I have not been able to figure out how to turn off cellular data.
Any information is greatly appreciated.
Solution
This solution worked for me: https://sqa.stackexchange.com/questions/23646/how-can-i-switch-on-off-airplane-mode-and-wifi-using-appium?answertab=votes#tab-top
You can also perform a really jank workaround. Note: I did this mainly for fun, do not promote the actual use of it ;)
#!/bin/bash
### SET Airplane Mode ON ###
adb shell am start -a android.settings.AIRPLANE_MODE_SETTINGS \
&& for i in {1..5}
do
adb shell input keyevent 20
done \
&& adb shell input keyevent 23 \
&& adb shell input keyevent 4;
### Run tests ###
### SET Airplane Mode OFF ###
# NOTE: When Airplane Mode is enabled in API 28, "Mobile network" is disabled. Additionally, since Android Setting's Network & internet
# is still running in the background, you'll have to select the down action two less times.
adb shell am start -a android.settings.AIRPLANE_MODE_SETTINGS \
&& for i in {1..3}
do
adb shell input keyevent 20
done \
&& adb shell input keyevent 23 \
&& adb shell input keyevent 4;
Answered By - Dillon C
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.