结构:分别有新增,搜索,修改,删除一共4个脚本。
在联调测试时,增加一个公共类common来打开设备。再建一个业务流类调用单个文件组成联调
# v1.0 实现新增笔记测试
import time
from appium.webdriver.webdriver import WebDriver
from selenium 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.144.101:5555'
# self.caps['appPackage'] = 'com.youdao.note'
# self. caps['appActivity'] = '.activity2.MainActivity t131'
#
# self.driver = WebDriver('http://127.0.0.1:4723/wd/hub', self.caps)
# self.driver.implicitly_wait(10)
pass
# 新增笔记的测试
def test_add(self):
# 等待10秒,直到对象x出现
el=WebDriverWait(self.driver,10).until(lambda x:x.find_element_by_id('com.android.packageinstaller:id/permission_allow_button'))
# # 假如对象el出现
if el:
# 点击允许按钮
self.driver.find_element_by_id('com.android.packageinstaller:id/permission_allow_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()
# 输入内容
self.driver.find_element_by_xpath('//*[@resource-id="com.youdao.note:id/note_content"]/android.widget.EditText').send_keys('textcontent')
# 输入标题
self.driver.find_element_by_id('com.youdao.note:id/note_title').send_keys('titlle')
# 点击完成按钮
self.driver.find_element_by_id('com.youdao.note:id/actionbar_complete_text').click()
# 为业务改的方法
def test_add_flow(self,driver):
# 等待10秒,直到对象x出现
el=WebDriverWait(driver,10).until(lambda x:x.find_element_by_id('com.android.packageinstaller:id/permission_allow_button'))
# # 假如对象el出现
if el:
# 点击允许按钮
driver.find_element_by_id('com.android.packageinstaller:id/permission_allow_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()
# 输入内容
driver.find_element_by_xpath('//*[@resource-id="com.youdao.note:id/note_content"]/android.widget.EditText').send_keys('textcontent')
# 输入标题
driver.find_element_by_id('com.youdao.note:id/note_title').send_keys('titlle')
# 点击完成按钮
driver.find_element_by_id('com.youdao.note:id/actionbar_complete_text').click()
def check_addnote(self):
title=self.driver.find_element_by_id('com.youdao.note:id/title').text
if __name__ == '__main__':
yd_addnote_obj=yd_addnote()
yd_addnote_obj.test_add()
yd_addnote_obj.check_addnote()
# 查询功能测试
import time
from appium.webdriver.webdriver import WebDriver
class yd_serchnote:
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.youdao.note'
# self.caps['appActivity'] = '.activity2.MainActivity t131'
#
# self.driver = WebDriver('http://127.0.0.1:4723/wd/hub', self.caps)
# self.driver.implicitly_wait(10)
pass
def test_searchnote(self):
# 点击搜索按钮
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("titlle")
# 点击搜索按钮
self.driver.find_element_by_id('com.youdao.note:id/search_button').click()
def test_searchnote_flow(self,driver):
# 点击搜索按钮
driver.find_element_by_id('com.youdao.note:id/search').click()
# 输入搜索关键字
driver.find_element_by_id('com.youdao.note:id/search_edit_view').send_keys("titlle")
# 点击搜索按钮
driver.find_element_by_id('com.youdao.note:id/search_button').click()
driver.get_screenshot_as_file('search.png')
time.sleep(3)
# 修改功能
from appium.webdriver.webdriver import WebDriver
import time
from selenium import webdriver
import selenium
class yd_editnote:
def test_editnote_flow(self,driver):
driver.find_element_by_id('com.youdao.note:id/title').click()
driver.find_element_by_id('com.youdao.note:id/edit').click()
# 修改内容
driver.find_element_by_xpath('//*[@resource-id="com.youdao.note:id/note_content"]/android.widget.EditText').send_keys("editcontent")
# 修改标题
driver.find_element_by_id('com.youdao.note:id/note_title').send_keys('edit')
# 点击完成
driver.find_element_by_id('com.youdao.note:id/actionbar_complete_text').click()
time.sleep(3)
# 获取修改后的标题
rtitle=driver.find_element_by_id('com.youdao.note:id/note_title').text
print(rtitle)
if rtitle=="edit":
print("修改成功")
else:
print("修改失败")
time.sleep(3)
# 删除测试
from appium.webdriver.webdriver import WebDriver
import selenium
from selenium import webdriver
class yd_deletenote:
def test_deletenotte(self,driver):
driver.find_element_by_id('com.youdao.note:id/menu_more').click()
# 点击展开菜单
driver.find_element_by_id('com.youdao.note:id/delete').click()
# 点击确定删除
driver.find_element_by_id('com.youdao.note:id/btn_ok').click()
num=driver.find_elements_by_class_name('android.widget.LinearLayout')
print(num)
if len(num)>0:
print("删除不成功")
driver.get_screenshot_as_file("deleteErro.png")
else:
print("删除成功")
driver.get_screenshot_as_file("deleteSuccess.png")
# 进行业务场景的测试(新增-查询-修改-删除)
# 加入新增功能脚本测试
import csv
from appium.webdriver.webdriver import WebDriver
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from youdaoyunproject.work_addnote import yd_addnote
from youdaoyunproject.work3_serchnote import yd_serchnote
from youdaoyunproject.work_addnote import yd_addnote
from youdaoyunproject.common import comm_class
from youdaoyunproject.work4_editnote import yd_editnote
from youdaoyunproject.work5_deletenote import yd_deletenote
# 加入新增脚本测试功能
if __name__ == '__main__':
# 实例化一个公共的类进行参数设置返回driver
commobj=comm_class()
driver=commobj.get_driver()
# 进行对象的实例化
addobj=yd_addnote()
searchobj=yd_serchnote()
editobj=yd_editnote()
deleteobj=yd_deletenote()
# 进行功能测试
addobj.test_add_flow(driver)
searchobj.test_searchnote_flow(driver)
editobj.test_editnote_flow(driver)
deleteobj.test_deletenotte(driver)
|