app的安装两种方式: 1 卸载安装 2 覆盖安装
逻辑: 如果包存在且选择卸载安装,则卸载再安装;否则直接安装
driver.is_app_installed(app_package) 是否安装
driver.remove_app(app_package) 卸载
driver.install_app(path) 安装
from appium import webdriver def install_app(app_package, path, is_cover=True): """ :param app_package: 安装包名 :param path: 安装包路径 :param is_cover: 是否覆盖安装 True-覆盖安装,False-卸载安装 """ desired_caps = dict() desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '5' desired_caps['deviceName'] = 'nox' # 系统应用 desired_caps['appPackage'] = 'com.android.settings' desired_caps['appActivity'] = '.Settings' driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) # 卸载安装 if driver.is_app_installed(app_package) and is_cover is False: driver.remove_app(app_package) #卸载 print(app_package+"已卸载") try: driver.install_app(path) #安装 except BaseException: print("安装失败") else: print(app_package + "app安装成功,安装路径:" + path) # 退出 driver.quit()