手机app业务场景普通脚本设计(文件传参,输出测试报告)

测试数据:
在这里插入图片描述
公共模块:

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"
    def get_driver(self):
        driver=WebDriver('http://127.0.0.1:4723/wd/hub',self.caps)
        driver.implicitly_wait(15)
        return driver

新增模块:

class addnote():
    def add1(self,driver,title,content):
        # 点击同意按钮
        driver.find_element_by_id("com.youdao.note:id/btn_ok").click()
        # 点击取消按钮
        driver.find_element_by_id("com.youdao.note:id/btn_cancel").click()
        # 点击新增按钮
        driver.find_element_by_id("com.youdao.note:id/add_note").click()
        # 点击新建笔记
        driver.find_element_by_id("com.youdao.note:id/add_icon").click()
        # 点击“ALLOW"按钮
        driver.find_element_by_id("com.android.packageinstaller:id/permission_allow_button").click()
        # 输入内容
        driver.find_element_by_xpath(
            "//*[@resource-id='com.youdao.note:id/note_content']/android.widget.EditText").send_keys(content)
        # 输入标题
        driver.find_element_by_id("com.youdao.note:id/note_title").send_keys(title)
        # 点击"完成"按钮
        driver.find_element_by_id("com.youdao.note:id/actionbar_complete_text").click()

查询模块:

class searchnote():
    def search1(self,driver,title):
        # 点击搜索按钮
        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(title)
        # 点击搜索
        driver.find_element_by_id("com.youdao.note:id/action_btn").click()

修改模块:

import time
class editnote:
    def edit1(self,driver, title1, content1):
        # 选择要修改的笔记
        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(content1)
        # 修改标题
        driver.find_element_by_id("com.youdao.note:id/note_title").send_keys(title1)
        # 点击完成
        driver.find_element_by_id("com.youdao.note:id/actionbar_complete_text").click()
        time.sleep(3)

删除模块:

import time
class deletenote():
    def delete1(self,driver):
        # 选择要删除的笔记
        driver.find_element_by_xpath(
            "//*[@resource-id='com.youdao.note:id/actionbar_menu_layout']/android.widget.ImageView[3]").click()
        # 点击删除
        driver.find_element_by_id('com.youdao.note:id/delete').click()
        # 点击确定
        driver.find_element_by_id('com.youdao.note:id/btn_ok').click()
        time.sleep(2)
        result=driver.find_elements_by_class_name("android.widget.RelativeLayout")
        driver.quit()
        if len(result)>0:
            return 0
        else:
            return 1

主函数调用模块:

import csv
from youdao.yewuchangjing.addnote2 import addnote
from youdao.commom import com
from youdao.yewuchangjing.searchnote2 import searchnote
from youdao.yewuchangjing.editnote2 import editnote
from youdao.yewuchangjing.deletenote2 import deletenote
if __name__ == '__main__':
    comobj = com()
    addobj = addnote()
    searchobj = searchnote()
    editobj = editnote()
    deleteobj = deletenote()
    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]
        driver = comobj.get_driver()
        addobj.add1(driver, title, content)
        searchobj.search1(driver, title)
        editobj.edit1(driver, title1, content1)
        r=deleteobj.delete1(driver)
        file1=open("testflow.csv","a",newline="")
        w=csv.writer(file1)
        if r==1:
            row.append("测试成功")
            w.writerow(row)
        else:
            row.append("测试失败")
            w.writerow(row)
        file1.close()

运行结束后生成的结果文件:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值