简体   繁体   English

如何断开互联网与appium Python的连接

[英]How to disconnect Internet from appium Python

I am doing Appium Automation in "Python", I need to ask, what is the method, which can disconnect the internet of mobile device via appium. 我正在用“ Python”进行Appium自动化,我想问一下可以通过appium断开移动设备互联网连接的方法是什么。 In Python. 在Python中。 and Also do share with me, how can I connect the disconnect Internet as well. 并且也要与我分享,如何连接断开的Internet。

In case somebody still looking for the answer - this is what worked out for me: 如果有人还在寻找答案,这对我来说是可行的:

self.driver.open_notifications()
self.driver.find_element_by_xpath('//android.widget.Switch[@content-desc="Airplane mode"]').click()
self.driver.back()

As Mobile device can be getting Internet/packet data through cellular network(eg 3G/4G) and WiFi both, one way to completely disconnect Internet can be to put the device in to Airplane/Flight mode. 由于移动设备可以同时通过蜂窝网络(例如3G / 4G)和WiFi获取Internet /分组数据,因此一种完全断开Internet连接的方法是将设备置于“飞机/飞行”模式。

This can be done through Appium by launching settings Activity and by toggling the Flight mode button. 可以通过启动“活动”设置和切换“飞行模式”按钮来通过Appium完成此操作。

On my Android S2 tab Settings Activity( com.android.settings.Settings ) is under com.android.settings package . 在我的Android S2选项卡上,设置活动( com.android.settings.Settings )在com.android.settings package

You can trigger adb commands through Python subprocess library as well to disable and enable wifi and mobile data. 您还可以通过Python subprocess库触发adb命令,以禁用和启用wifi和移动数据。 Following SO post is having details of these adb commands: 以下SO帖子详细介绍了这些adb命令:

Is there an ADB command to enable/disable mobile data?(Rooted Device) 是否有ADB命令启用/禁用移动数据?(Rooted Device)

Two ways to do it. 有两种方法。

  1. Toggle the mobile data on/off button by opening the data usage settings page using adb command. 通过使用adb命令打开数据使用设置页面来切换移动数据打开/关闭按钮。

You need to find appPackage and appActivity of data usage page 您需要找到appPackage和appActivity的数据使用情况页面

how to get appPackage and appActivity by adb 如何通过adb获取appPackage和appActivity

  1. There is inbuilt library for device having Android version <=6 to enable disable airplane mode. 对于具有Android版本<= 6的设备,有一个内置库来启用禁用飞行模式。

In robotframework it is called Set Network connection status 在robotframework中,它称为“ 设置网络连接状态”

In python it would be similar I guess, just check. 在python中,我猜类似,只需检查即可。

For Android version > 6, there is no library to do the task, you need to toggle as you are doing for mobile data 对于Android版本> 6,没有库可以执行此任务,您需要在处理移动数据时进行切换

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

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