android - Espresso : Toggle Network State

标签 android kotlin network-programming android-espresso

我目前正在开发涵盖离线功能的 Espresso 测试套件。为了实现这些测试,我需要创建一个方法,我可以调用它来打开/关闭网络连接。到目前为止,我已经能够切换 WiFi,但我一直无法弄清楚如何关闭蜂窝数据。

非常感谢任何信息。

最佳答案

这个解决方案对我有用: https://sqa.stackexchange.com/questions/23646/how-can-i-switch-on-off-airplane-mode-and-wifi-using-appium?answertab=votes#tab-top

您还可以执行真正 卡顿解决方法。 注意:我这样做主要是为了好玩,不促进实际使用它;)

#!/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;

关于android - Espresso : Toggle Network State,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52450414/

相关文章:

android - Cordova 5.0.0 android 应用程序无法使用 android 4.0.0 连接到互联网

arrays - Kotlin - 向空数组添加值

kotlin - Kotlin 文档中的术语 "Changing type from unsigned type to signed counterpart (and vice versa) is a binary incompatible change"是什么意思?

c# - 如何在 C# 中使用 ResolveIpNetEntry2

android - 对话框有圆角但没有透明边缘

通过 Imageview 进行 Android 手势检测

Android:从 View 传递触摸事件

kotlin - Kotlin链式通话中的评论

python - 如何向 IGMP 设备发送 UDP 数据报?

linux - 在linux内核中开发简单的net_device