Espresso:切换网络状态
Espresso: Toggle Network State
我目前正在开发涵盖离线功能的 Espresso 测试套件。为了实现这些测试,我需要创建一个方法,我可以调用它来切换 on/off 网络连接。到目前为止,我已经能够切换 WiFi,但我一直无法弄清楚如何关闭蜂窝数据。
非常感谢任何信息。
您还可以执行 真正 卡顿解决方法。
注:我这样做主要是为了好玩,不提倡实际使用;)
#!/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;
我目前正在开发涵盖离线功能的 Espresso 测试套件。为了实现这些测试,我需要创建一个方法,我可以调用它来切换 on/off 网络连接。到目前为止,我已经能够切换 WiFi,但我一直无法弄清楚如何关闭蜂窝数据。
非常感谢任何信息。
您还可以执行 真正 卡顿解决方法。 注:我这样做主要是为了好玩,不提倡实际使用;)
#!/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;