adb命令安装卸载apk

import os
import time
adb_devices = 'adb devices'

apkpath = r'E:\appium\com.tencent.mobileqq.apk'

adb_install = 'adb install ' + apkpath

adb_uninstall = 'adb uninstall com.tencent.mobileqq'

os.system(adb_devices)
os.system(adb_install)
time.sleep(20)
os.system(adb_uninstall)

控制台打印出来

C:\Users\Administrator\AppData\Local\Programs\Python\Python35\python.exe E:/PyCharm/appium/adb.py
List of devices attached 
a5ca2448	device

	pkg: /data/local/tmp/com.tencent.mobileqq.apk
Success
5099 KB/s (60273923 bytes in 11.541s)
Success

Process finished with exit code 0

遇到的坑:
安装时:
1.Failure [INSTALL_CANCELED_BY_USER]
原因,未将手机的允许通过USB安装软件开关打开。
2.Failure [DELETE_FAILED_INTERNAL_ERROR]
原因,install后面没加空格
3.Failure [Invalid apk]
原因,apk起名为中文名,改成英文即可

卸载时:
Failure [DELETE_FAILED_INTERNAL_ERROR]

原因:卸载命令只要包名,不是文件名,更不能加后缀.apk

你可能感兴趣的:(自动化测试)