1.定义安装卸载类,包括初始化属性,安装卸载方法,检查方法
2.继承v1.添加新的方法测试新的手机。也可以合并写在同一文件下
from appium.webdriver.webdriver import WebDriver
# 定义测试安装卸载类
class yd_install_remove_v1():
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是否已经安装过了
if self.driver.is_app_installed('com.youdao.note'):
# 安装app,路径+安装包名,卸载app,包名
self.driver.remove_app('com.youdao.note')
self.driver.install_app('D:\phonetest\youdaoyunproject\youdaoyunbiji_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:弹出界面上抓取“拒绝”链接.判断是否可用。如果有,可用,如果没有,不可用
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_v1()
yd_install_remove_obj.test_install_remove()
yd_install_remove_obj.check_install()
from appium.webdriver.webdriver import WebDriver
# 继承导入v1类
from youdaoyunproject.work1_install_remove import yd_install_remove_v1
class yd_istall_remove_v2(yd_install_remove_v1):
def __init__(self):
self.caps = {}
self.caps["automationName"] = "UiAutomator2"
self.caps['platformName'] = 'Android'
def setdevice_6(self):
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 setdevice_7(self):
self.caps['platformVersion'] = '7.1'
self.caps['deviceName'] = '192.168.144.102:5555'
self.caps['appPackage'] = 'com.android.launcher3'
self.caps['appActivity'] = '.Launcher t4'
self.driver = WebDriver('http://127.0.0.1:4723/wd/hub', self.caps)
if __name__ == '__main__':
yd_install_remove_v2_obj=yd_istall_remove_v2()
# 6.0版本测试
yd_install_remove_v2_obj.setdevice_6()
yd_install_remove_v2_obj.test_install_remove()
yd_install_remove_v2_obj.check_install()
# 7.1版本测试
yd_install_remove_v2_obj=yd_istall_remove_v2()
yd_install_remove_v2_obj.setdevice_7()
yd_install_remove_v2_obj.test_install_remove()
yd_install_remove_v2_obj.check_install()
本次新增知识:
判断app是否已经安装:
is_app_installed
if self.driver.is_app_installed('com.youdao.note'):