Appium之常用python+adb指令集合

  • 2019 年 10 月 10 日
  • 筆記

在编写脚本过程中,特别是使用python脚本操作Android设备时,常常需要去调用adb指令来辅助测试,下面就列举下在做自动化测试时经常使用的adb指令

1、查看包名和activity

adb shell dumpsys window w |findstr / |findstr name=

2、熄屏、亮屏操作

os.popen("adb shell input keyevent 26") #操作设备的power键

3、重启设备操作

os.popen("adb reboot") #直接(热)重启

4、打开指定应用(package/.activity)

os.popen("adb shell am start -n cn.kuwo.kwmusiccar/cn.kuwo.kwmusiccar.WelcomeActivity") # 打开酷我 os.popen("adb shell am start -n com.edog.car/com.kaolafm.auto.home.MainActivity") # 打开考拉电台 os.popen("adb shell am start -n cn.yunovo.car.settings/cn.yunovo.car.settings.SettingsListActivity") # 打开设置 os.popen("adb shell am start -n cn.yunovo.nxos.bt/cn.yunovo.nxos.bt.activitys.BluetoothActivity") # 打开蓝牙电话 os.popen("adb shell am start -n com.aispeech.aios/.MainActivity") #打开语音助手

5、切换至后台(HOME按键)

os.popen("adb shell input keyevent 3") #切换至后台

6、查看系统内存情况

os.popen("adb shell dumpsys meminfo")

7、获取wifi信息

os.popen(" adb shell dumpsys wifi ")

8、查看进程占用CPU情况

os.popen(" top -m 20 -d 2 ") #top -m 进程数 -d 秒

9、查看设备电量信息

os.popen(" dumpsys battery ")

10、截图操作

os.popen(" adb shell screencap -p /sdcard/screen.png ")

11、跑Monkey

adb shell monkey -p com.spt.carengine.txz.voice -s 1000 –ignore-crashes –ignore-timeouts –monitor-native-crashes -v -v 100000000

12、安装和卸载APK

adb install xx.apk #安装apk adb uninstall xx.apk #卸载apk

13、查看设备名

adb devices

14、通过WiFi连接设备

adb connect 10.0.0.123