安卓手机自动化测试_app安装卸载

目的:实现安卓手机app安装卸载,并且兼容性测试

#父类

#注意点:类初始化、is_app_installed、remove_app、insall_app、is_enable、智能等待

from appium.webdriver.webdriver import WebDriver
import time
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait

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.111.101:5555'
        self.caps['appPackage'] = 'com.android.launcher3'
        self.caps['appActivity'] = '.Launcher'
        self.driver=WebDriver('htp://127.0.0.1:4723/wd/hub',self.caps)
    def test_install_remove(self):
        #is_app_installed验证是否存在app,存在返回true
        if self.driver.is_app_installed('com.youdao.note'):
            self.driver.remove_app('com.youdao.note')
        self.driver.install_app(r'F:\python\app\youdaoyunbiji_84.apk')
    def check_install(self):
        self.caps['appPackage'] = 'com.youdao.note'
        self.caps['appActivity'] = '.activity2.MainActivity'
        self.driver = WebDriver('http://127.0.0.1:4723', self.caps)
        #time.sleep(3)
        #elresult = self.driver.find_element_by_id('com.android.packageinstaller:id/permission_deny_button').is_enabled()
        #智能等待
        # lambda匿名函数x,内容x.find_element_by_id('com.android.packageinstaller:id/permission_deny_button'),函数作用判断元素是否存在
        elresult=+WebDriverWait(self.driver,10).until(lambda x:x.find_element_by_id('com.android.packageinstaller:id/permission_deny_button'))
        if elresult:
            print('ok')
        else:
            print('bad')

if __name__ == '__main__':
    workobj=YD_install_remove()
    workobj.test_install_remove()
    workobj.check_install()

方法一:子类继承父类,修改属性

#兼容性测试,继承父类
from appium.webdriver.webdriver import WebDriver
import time
from youdaoproject.work1_install_remove import YD_install_remove

class YD_install_removeV2(YD_install_remove):
    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.111.101:5555'
        self.caps['appPackage'] = 'com.android.launcher3'
        self.caps['appActivity'] = '.Launcher'
        self.driver = WebDriver('htp://127.0.0.1:4723/wd/hub', self.caps)
    def setdevice_7(self):
        self.caps['platformVersion'] = '7.0'
        self.caps['deviceName'] = '192.168.111.102:5555'
        self.caps['appPackage'] = 'com.android.launcher3'
        self.caps['appActivity'] = '.Launcher t2'
        self.driver = WebDriver('htp://127.0.0.1:4723/wd/hub', self.caps)
if __name__ == '__main__':
    YD_install_removeV2obj=YD_install_removeV2()
    #验证6.0版本测试
    YD_install_removeV2.setdevice_6()
    YD_install_removeV2.test_install_remove()
    YD_install_removeV2.check_install()
    #验证7.0版本测试
    YD_install_removeV2.setdevice_7()
    YD_install_removeV2.test_install_remove()
    YD_install_removeV2.check_install()

方法二:从csv文件读取属性,重新赋值对象属性

import csv
from appium.webdriver.webdriver import WebDriver
from youdaoproject.work1_install_remove import YD_install_remove

if __name__ == '__main__':
    YD_install_remove_obj=YD_install_remove()
    file=open('testpara','r')
    table=csv.reader(file)
    #对象的属性赋值
    YD_install_remove_obj.caps={}
    YD_install_remove_obj.caps['automationName']='UiAutomator2'
    YD_install_remove_obj.caps['platformName'] = 'Android'
    for row in table:
        YD_install_remove_obj.caps[row[0]]=row[1]
        YD_install_remove_obj.caps[row[2]] = row[3]
        YD_install_remove_obj.caps[row[4]] = row[5]
        YD_install_remove_obj.driver=WebDriver('http://127.0.0.1',YD_install_remove_obj.caps)
        YD_install_remove_obj.test_install_remove()
        YD_install_remove_obj.check_install()

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值