如何通过代码安装app
from appium.webdriver.webdriver import WebDriver # 定义测试安装卸载类 class yd_install_remove(): def __init__(self): self.caps={} self.caps["automationName"] = "UiAutomator2" self.caps['platformName'] = 'Android' self.caps['platformVersion'] = '6.0' self.caps['deviceName'] = '192.168.144.101:5555' self.caps['appPackage'] = 'com.android.launcher3' self.caps['appActivity'] = '.Launcher t49' self.driver=WebDriver('http://127.0.0.1:4723/wd/hub',self.caps) def test_install_remove(self): # 安装app,路径+安装包名,卸载app,包名 self.driver.remove_app('com.youdao.note') self.driver.install_app('D:phonetestyoudaoyunprojectyoudaoyunbiji_84.apk') def check_install(self): # s1:安装后启动有道云 self.caps['appPackage'] = 'com.youdao.note' self.caps['appActivity'] = '.activity2.MainActivity t58' self.driver = WebDriver('http://127.0.0.1:4723/wd/hub', self.caps) # s2:d出界面上抓取“拒绝”链接.判断是否可用。如果有,可用,如果没有,不可用 el = self.driver.find_element_by_id('com.android.packageinstaller:id/permission_deny_button').is_enabled() print(el) # s3:如果链接存在的,name打印“安装成功 if el: print("安装成功") # 否则打印安装失败 else: print('安装失败') if __name__ == '__main__': # 实例化,然后调用方法 yd_install_remove_obj=yd_install_remove() yd_install_remove_obj.test_install_remove() yd_install_remove_obj.check_install()
1.先把对应的apk文件放在英文路径下面
2.使用安装方法:driver.install_app("路径+安装包名")
安装后启动有道云,该软件正常会d出特定小窗口。在d出上抓取“拒绝”链接.如果有表示安装成功,如果没有表示安装失败
本次知识点:包的安装和卸载
卸载app:driver.install_app('路径+包名')
self.driver.install_app('D:phonetestyoudaoyunprojectyoudaoyunbiji_84.apk')
安装app:driver.remove_app('包名')
driver.remove_app('com.youdao.note')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)