简体   繁体   中英

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. In Python. and Also do share with me, how can I connect the disconnect Internet as well.

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.

This can be done through Appium by launching settings Activity and by toggling the Flight mode button.

On my Android S2 tab Settings Activity( com.android.settings.Settings ) is under com.android.settings package .

You can trigger adb commands through Python subprocess library as well to disable and enable wifi and mobile data. Following SO post is having details of these adb commands:

Is there an ADB command to enable/disable mobile data?(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.

You need to find appPackage and appActivity of data usage page

how to get appPackage and appActivity by adb

  1. There is inbuilt library for device having Android version <=6 to enable disable airplane mode.

In robotframework it is called Set Network connection status

In python it would be similar I guess, just check.

For Android version > 6, there is no library to do the task, you need to toggle as you are doing for mobile data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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