测试数据:
公共模块:
#公共模块
from appium.webdriver.webdriver import WebDriver
class com:
def __init__(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(15)
新增笔记模块:
#新增笔记测试
import csv
from youdao.commom import com
from selenium.webdriver.support.wait import WebDriverWait
class yd_addnote(com):
def add(self,title,content):
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(content)
#输入标题
self.driver.find_element_by_id("com.youdao.note:id/note_title").send_keys(title)
#点击"完成"按钮
self.driver.find_element_by_id("com.youdao.note:id/actionbar_complete_text").click()
def check_note(self,title):
result=self.driver.find_element_by_id("com.youdao.note:id/title").text
file1=open("save.csv","a",newline="")
w=csv.writer(file1)
if result==title:
row.append("测试通过")
w.writerow(row)
else:
row.append("测试失败")
w.writerow(row)
file1.close()
if __name__ == '__main__':
file=open('addnote1.csv',"r")
table=csv.reader(file)
for row in table:
title=row[0]
content=row[1]
yd_addnote1=yd_addnote()
yd_addnote1.add(title,content)
yd_addnote1.check_note(title)
修改笔记模块:
import csv
import time
from youdao.yewuchangjing.addnote1 import yd_addnote
class yd_editnote(yd_addnote):
def edit(self,title1,content1):
#选择要修改的笔记
self.driver.find_element_by_id('com.youdao.note:id/title').click()
#点击修改
self.driver.find_element_by_id("com.youdao.note:id/edit").click()
#修改内容
self.driver.find_element_by_xpath(
"//*[@resource-id='com.youdao.note:id/note_content']/android.widget.EditText").send_keys(content1)
#修改标题
self.driver.find_element_by_id("com.youdao.note:id/note_title").send_keys(title1)
#点击完成
self.driver.find_element_by_id("com.youdao.note:id/actionbar_complete_text").click()
time.sleep(3)
def check_edit(self,title1):
result=self.driver.find_element_by_id('com.youdao.note:id/note_title').text
file1=open("edit_result.csv", "a", newline="")
w=csv.writer(file1)
if result==title1:
row.append("修改成功")
w.writerow(row)
else:
row.append("修改失败")
w.writerow(row)
file1.close()
if __name__ == '__main__':
yd_editnoteobj=yd_editnote()
file=open('addnote1.csv',"r")
table=csv.reader(file)
for row in table:
title=row[0]
content=row[1]
title1=row[2]
content1=row[3]
yd_editnoteobj=yd_editnote()
yd_editnoteobj.add(title,content)
yd_editnoteobj.edit(title1,content1)
yd_editnoteobj.check_edit(title1)
运行时先调用公共模块进入有道云笔记,再调用新增笔记模块的add方法新增一条笔记,再调用修改笔记模块的edit方法和check_edit方法修改笔记和写入测试结果到文档。
测试结果文档: