1、解决方法
关闭wifi,重新开启
2、关闭wifi、开启wifi方法封装
from appium.webdriver.connectiontype import ConnectionType
def set_no_connection(driver):
"""
设置成-无网络
:param driver:
:return:
"""
driver.set_network_connection(ConnectionType.NO_CONNECTION)
return driver
def set_wifi(driver):
"""
设置成-开启wifi
:param driver:
:return:
"""
driver.set_network_connection(ConnectionType.WIFI_ONLY)
return driver
3、开启 or 关闭 wifi ,对应的appium 日志查看
// 开wifi, 没开数据流量+飞行模式
# 关闭 wifi
2021-12-29 03:24:25:558 - [HTTP]
2021-12-29 03:24:25:563 - [HTTP] --> POST /wd/hub/session/8738855f-50ab-40e9-a361-6e021465870f/network_connection
2021-12-29 03:24:25:563 - [HTTP] {"parameters":{"type":0}}
2021-12-29 03:24:25:568 - [debug] [W3C (8738855f)] Calling AppiumDriver.setNetworkConnection() with args: [0,"8738855f-50ab-40e9-a361-6e021465870f"]
2021-12-29 03:24:25:568 - [AndroidDriver] Setting network connection
2021-12-29 03:24:25:568 - [AndroidDriver] Getting network connection
2021-12-29 03:24:25:569 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell settings get global airplane_mode_on'
2021-12-29 03:24:25:593 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell settings get global wifi_on'
2021-12-29 03:24:25:617 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell settings get global mobile_data'
2021-12-29 03:24:25:639 - [AndroidDriver] Not changing airplane mode, since it is already disabled
2021-12-29 03:24:25:641 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell am broadcast -a io.appium.settings.wifi -n io.appium.settings/.receivers.WiFiConnectionSettingReceiver --es setstatus disable'
2021-12-29 03:24:25:681 - [AndroidDriver] Not changing data connection state, since it is already disabled
2021-12-29 03:24:25:682 - [AndroidDriver] Getting network connection
2021-12-29 03:24:25:682 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell settings get global airplane_mode_on'
2021-12-29 03:24:25:707 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell settings get global wifi_on'
2021-12-29 03:24:25:735 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell settings get global mobile_data'
2021-12-29 03:24:25:760 - [debug] [W3C (8738855f)] Responding to client with driver.setNetworkConnection() result: 0
# 开启 wifi
2021-12-29 03:26:52:920 - [HTTP] --> POST /wd/hub/session/0544bf54-173d-4009-beab-cf8b6877a7dc/network_connection
2021-12-29 03:26:52:920 - [HTTP] {"parameters":{"type":2}}
2021-12-29 03:26:52:923 - [debug] [W3C (0544bf54)] Calling AppiumDriver.setNetworkConnection() with args: [2,"0544bf54-173d-4009-beab-cf8b6877a7dc"]
2021-12-29 03:26:52:923 - [AndroidDriver] Setting network connection
2021-12-29 03:26:52:923 - [AndroidDriver] Getting network connection
2021-12-29 03:26:52:923 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell settings get global airplane_mode_on'
2021-12-29 03:26:52:993 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell settings get global wifi_on'
2021-12-29 03:26:53:058 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell settings get global mobile_data'
2021-12-29 03:26:53:094 - [AndroidDriver] Not changing airplane mode, since it is already disabled
2021-12-29 03:26:53:095 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell am broadcast -a io.appium.settings.wifi -n io.appium.settings/.receivers.WiFiConnectionSettingReceiver --es setstatus enable'
2021-12-29 03:26:53:129 - [AndroidDriver] Not changing data connection state, since it is already disabled
2021-12-29 03:26:53:130 - [AndroidDriver] Getting network connection
2021-12-29 03:26:53:130 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell settings get global airplane_mode_on'
2021-12-29 03:26:53:156 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell settings get global wifi_on'
2021-12-29 03:26:53:185 - [debug] [ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s ed0335e2 shell settings get global mobile_data'
2021-12-29 03:26:53:217 - [debug] [W3C (0544bf54)] Responding to client with driver.setNetworkConnection() result: 2