有道云笔记app项目:unittest框架脚本—新增+查询+删除笔记(核心技术:unittest+DDT+类的封装)

将setUp和tearDown方法封装在BaseTest脚本:

import unittest2
from appium.webdriver.webdriver import WebDriver
class BaseTest(unittest2.TestCase):
    def setUp(self):
        self.caps={}
        self.caps['automationName']='UiAutomator2'
        self.caps["newCommandTimeout"] = "5000"
        self.caps['platformName'] = 'Android'
        self.caps["platformVersion"] = "6.0"
        self.caps["deviceName"]="192.168.75.103:5555"
        self.caps["appPackage"]="com.youdao.note"
        self.caps["appActivity"]=".activity2.SplashActivity"
        self.driver=WebDriver('http://127.0.0.1:4723/wd/hub',self.caps)
        self.driver.implicitly_wait(10)
    def tearDown(self):
        self.driver.quit()

配置文件addnote1.csv:
在这里插入图片描述

import time
import ddt
from func1.csvreader import reader
from test_case1.BaseTest import BaseTest
from selenium.webdriver.support.wait import WebDriverWait
@ddt.ddt
class delete_test(BaseTest):
    table=reader(r"\addnote1.csv")
    @ddt.data(*table)
    def test_case(self,row):
        self.driver.implicitly_wait(10)
        aa=WebDriverWait(self.driver,15).until(lambda x: x.find_element_by_id("com.youdao.note:id/btn_ok"))
        if aa:
            # 点击同意按钮
            self.driver.find_element_by_id("com.youdao.note:id/btn_ok").click()
            # 点击取消按钮
            self.driver.find_element_by_id("com.youdao.note:id/btn_cancel").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_icon").click()
            # 点击“ALLOW"按钮
            self.driver.find_element_by_id("com.android.packageinstaller:id/permission_allow_button").click()
            # 输入内容
            self.driver.find_element_by_xpath(
                "//*[@resource-id='com.youdao.note:id/note_content']/android.widget.EditText").send_keys(row[1])
            # 输入标题
            self.driver.find_element_by_id("com.youdao.note:id/note_title").send_keys(row[0])
            # 点击"完成"按钮
            self.driver.find_element_by_id("com.youdao.note:id/actionbar_complete_text").click()
            # 获取新增成功后的标题内容
            result = self.driver.find_element_by_id("com.youdao.note:id/title").text
            # 断言判断
            self.assertEqual(row[0],result)
            # 点击搜索按钮
            self.driver.find_element_by_id('com.youdao.note:id/search').click()
            # 输入搜索关键字
            self.driver.find_element_by_id('com.youdao.note:id/search_edit_view').send_keys(row[0])
            # 点击搜索按钮
            self.driver.find_element_by_id('com.youdao.note:id/action_btn').click()
            # 获取搜索后的标题内容
            result=self.driver.find_element_by_id("com.youdao.note:id/title").text
            # 断言判断
            self.assertEqual(row[0],result)
            # 选择要删除的笔记
            self.driver.find_element_by_id('com.youdao.note:id/title').click()
            self.driver.find_element_by_xpath(
                "//*[@resource-id='com.youdao.note:id/actionbar_menu_layout']/android.widget.ImageView[3]").click()
            # 点击删除
            self.driver.find_element_by_id('com.youdao.note:id/delete').click()
            # 点击确定
            self.driver.find_element_by_id('com.youdao.note:id/btn_ok').click()
            time.sleep(3)
            #获取删除的结果
            result=self.driver.find_elements_by_class_name('android.widget.LinearLayout')
            #断言
            self.assertTrue(len(result)<=0)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值