Appium自身有安装卸载,判断应用是否安装的方法:
如下:
install_app(self,app_path)通过给予的路径,安装app
is_app_installed(self, bundle_id) 检查指定的包,是否安装。返回True/False
remove_app(self, app_id) 通过app_id卸载apk
但是我实际测试中发现有不成功的现象,所以自己看了下源码,是通过adb命令来实现的,就自己封装了一下:
def install_app(self):
'''
安装app
:return:
'''
app_path = os.path.dirname(os.path.realpath(__file__)) + "\\app\\TopSAP(3.4.1.2.0.4).apk"
result_file = os.popen("adb install " + app_path)
result = result_file.read()
if "Success" in result:
log.info("应用卸载成功")
elif "Failure" in result:
log.error("应用卸载失败")
def uninstall_app(self):
"""
卸载应用
:return:
"""
result_file = os.popen("adb uninstall com.topsec.topsap")
result = result_file.read()
if "Success" in result:
log.info("应用卸载成功")
elif "Failure" in result:
log.error("应用卸载失败")
def is_app_installed(self):
'''
判断应用是否已经安装
:return: True,已经安装,False未安装
'''
result = os.popen("adb shell pm list package")
if "com.top.sap" in result.read():
log.info("应用已安装")
return True
else:
log.info("应用未安装")
return False