csv格式测试数据文件:
公共模块:
#公共模块
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
print(result)
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)
运行后生成的文件: