安卓手机自动化测试_新增note

#隐式等待、智能等待、重载父类、适应业务场景调用做的改动

#父类

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

class yd_addnote:
    def __init__(self):
        self.caps={}
        self.caps['automationName']='UIAutomator2'
        self.caps['platformName']='Android'
        self.caps['platformVersion']='6.0'
        self.caps['deviceName']='192.168.1410101:5555'
        self.caps['appPackage']='com.youdao.note'
        self.caps['appActivity']='.activity2.MainActivity t362'

        self.driver=WebDriver('http://127.0.0.1:4723/wd/hub',self.caps)
        #隐式等待
        self.driver.implicitly_wait(10)
        #业务场景下,初始化类pass掉
        #pass

    def test_addnote(self):
        #智能等待
        el = WebDriverWait(self.driver, 10).until(lambda x: x.find_element_by_id(
            'com..android.packageinstaller:id/permission_a;;ow_button'))
        if el:
            # 点击允许按钮
            self.driver.find_element_by_id('com.android.packageinstaller:id/permission_a;;ow_button').click()
            # 点击新建按钮
            self.driver.find_element_by_id('com.youdao.note:id/add_note').click()
            # 点击新建笔记
            self.driver.find_element_by_id('com.youdao.note:id/add_note_floater_add_note').click()
            # 点击取消按钮
            self.driver.find_element_by_id('com.youdao.note:id/btn_cancel').click()
            # 输入内容
            # xpath定位
            self.driver.find_element_by_xpath(
                "//*[@resource-id='com.youdao.note:id/note_content']/android.widget.EditText").send_keys('testcontent')

            # 输入标题
            self.driver.find_element_by_id('com.youdao.note:id/note_title').send_keys('testtitle')
            # 点击完成按钮
            # class_name定位
            self.driver.find_element_by_class_name('android.support.done').click()

    #业务场景下掉用,传入公共类的driver
    def test_addnote_flow(self,driver):
        # 智能等待
        el = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_id(
            'com..android.packageinstaller:id/permission_a;;ow_button'))
        if el:
            # 点击允许按钮
            driver.find_element_by_id('com.android.packageinstaller:id/permission_a;;ow_button').click()
            # 点击新建按钮
            driver.find_element_by_id('com.youdao.note:id/add_note').click()
            # 点击新建笔记
            driver.find_element_by_id('com.youdao.note:id/add_note_floater_add_note').click()
            # 点击取消按钮
            driver.find_element_by_id('com.youdao.note:id/btn_cancel').click()
            # 输入内容
            # xpath定位
            driver.find_element_by_xpath(
                "//*[@resource-id='com.youdao.note:id/note_content']/android.widget.EditText").send_keys('testcontent')

            # 输入标题
            driver.find_element_by_id('com.youdao.note:id/note_title').send_keys('testtitle')
            # 点击完成按钮
            # class_name定位
            driver.find_element_by_class_name('android.support.done').click()

    def check_addnote(self):
        title=self.driver.find_element_by_id('com.youdao.note:id/title').text
        print(title)

#子类,重载父类

import csv

from youdaoproject.work2_addnote import yd_addnote
from selenium.webdriver.support.wait import WebDriverWait

class yd_addnoteV2(yd_addnote):
    #重载父类
    def test_addnote(self,title,content):
        #智能等待
        el=WebDriverWait(self.driver,10).until(lambda x: x.find_element_by_id(
            'com..android.packageinstaller:id/permission_a;;ow_button'))
        if el:
            #点击允许按钮
            self.driver.find_element_by_id('com.android.packageinstaller:id/permission_a;;ow_button').click()
            #点击新建按钮
            self.driver.find_element_by_id('com.youdao.note:id/add_note').click()
            #点击新建笔记
            self.driver.find_element_by_id('com.youdao.note:id/add_note_floater_add_note').click()
            #点击取消按钮
            self.driver.find_element_by_id('com.youdao.note:id/btn_cancel').click()
            #输入内容
            #xpath定位
            self.driver.find_element_by_xpath(
                "//*[@resource-id='com.youdao.note:id/note_content']/android.widget.EditText").send_keys(content)

            #输入标题
            self.driver.find_element_by_id('com.youdao.note:id/note_title').send_keys(title)
            #点击完成按钮
            #class_name定位
            self.driver.find_element_by_class_name('android.support.done').click()

    def check_addnote(self,title):
        rtitle=self.driver.find_element_by_id('com.youdao.note:id/title').text
        if(rtitle==title):
            return 1
        else:
            return 0

if __name__ == '__main__':
    file1=open('addnotedat.csv','r')
    table=csv.reader(file1)
    file2=open('addnotereport.csv','w',newline='')
    writer=csv.writer(file2)
    #类实例化放在循环外,类初始化只执行一次出错
    #yd_addnote_obj2 = yd_addnoteV2()
    for row in table:
        title=row[0]
        content=row[1]
        #每次循环内实例化一次!!!
        yd_addnote_obj2 = yd_addnoteV2()
        yd_addnote_obj2.test_addnote(title,content)
        result=yd_addnote_obj2.check_addnote(title)
        if result:
            row.append('测试通过')
            writer.writerow(row)
        else:
            row.append('测试失败')
            writer.writerow(row)
    file2.close()

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值