简体   繁体   English

如何使用 Appium 在 Android Emulator 中禁用互联网连接?

[英]How can i disable internet connectivity in Android Emulator with Appium?

I want to test the connectivity icon in 3 cases :我想在 3 种情况下测试连接图标:

  1. When the connection status is fine当连接状态良好时

  2. When few heartbeats were missed and/or if the web socket is closed.当很少有心跳丢失和/或网络套接字关闭时。

  3. When no internet没有网络的时候

In Case one i can test it because i'm always connected to the internet but others i can't.在第一种情况下,我可以测试它,因为我总是连接到互联网,但其他人则不能。

PS: I'm using TestNG with Appium and Java PS:我在 Appium 和 Java 中使用 TestNG

What do you suggest ?你有什么建议?

i use the below code to stop wifi connection in ios :我使用以下代码在 ios 中停止 wifi 连接:

Runtime rt = Runtime.getRuntime();
try {
    rt.exec("networksetup -setairportpower en0 off");
    System.out.println("Wifi OFF Successfully");
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

use below to on wifi:在 wifi 上使用以下:

rt.exec("networksetup -setairportpower en0 on");
driver.ConnectionType = ConnectionType.None;

Or something like this.或类似的东西。 In this case driver is AndroidDriver instance for appium tests在这种情况下, driver是用于 appium 测试的 AndroidDriver 实例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM