【實施方法】
手機和電腦同時連接到同一個wifi上
1、開啟遠程adb
#開啟遠端adb,這一步需要手機通過USB連接到電腦
adb tcpip 5555
#結果如下:restarting in TCP mode port: 5555
#然后斷開USB
adb connect 192.168.3.2:5555
#其中192.168.3.2是手機的局域網IP地址
adb devices
#確認可以看到設備信息
2、通過adb命令啟動uiautomator2的agent
db shell /data/local/tmp/atx-agent -d
3、通過uiautomator2腳本連接手機執行用例
import uiautomator2 as u2
d = u2.connect_wifi('192.168.3.2')
print(d.info)
發現可以成功執行
PS:因為有些操作系統上uiautomator2的agent無法自動拉起,所以需要手動通過adb命令拉起