1、进行app测试前都需要连接手机,使用cmd窗口执行命令:adb devices
2、使用airtest无线连接手机时需要提前执行tcpip配置:adb tcpip 48887
一、通过os.system('输入命令')来执行
import os
cmd_devices = os.system('adb devices')
print(type(cmd_devices))
print('cmd_devices:', cmd_devices)
cmd_tcpip = os.system('adb tcpip 48887')
print(type(cmd_tcpip))
print('cmd_tcpip:', cmd_tcpip)
输出结果:
PS:执行成功,但输出的结果返回值为int类型的0,表示执行成功,此时无法获取到其他的返回信息。
二、通过os.popen('输入命令')来执行
cmd_devices = os.popen('adb devices')
print(type(cmd_devices))
#输出返回的类型是对象类型,通过read()方法读出返回值
print('cmd_devices:', cmd_devices.read())
cmd_tcpip = os.popen('adb tcpip 48887')
print(type(cmd_tcpip))
#输出返回的类型是对象类型,通过read()方法读出返回值
print('cmd_tcpip:', cmd_tcpip.read())