当前位置:网站首页>【Appium】通过设计关键字驱动文件来编写脚本
【Appium】通过设计关键字驱动文件来编写脚本
2022-04-23 17:39:00 【BetterFate!】
前言:通过关键字驱动文件,使脚本与测试用例分离,可以让代码较薄弱的人按格式填写用例所需参数,即可运行自动化脚本,同时也让代码更加简洁。
目录
一、设计驱动文件
本文通过csv文件来编写测试用例,除了用例基本要素ID、name、描述之外,为了和脚本关联起来还要加上元素定位方式、元素对象本身、操作方法、测试数据,当然实际情况还是按照项目要求来。
csv文件初步设计如下:
注意:测试步骤得按照实际测试时定位的顺序来写,不能乱
二、根据文件编写脚本
首先明确定位方法,我之前用的都是driver.find_element(By.ID, '元素id')这种By.方式的方法,但其实还有一种方法:driver.find_element('id', '元素id') 这种方法也是可以的。
其他对应的属性如下:
- ID = "id"
- XPATH = "xpath"
- LINK_TEXT = "link text"
- PARTIAL_LINK_TEXT = "partial link text"
- NAME = "name"
- TAG_NAME = "tag name"
- CLASS_NAME = "class name"
- CSS_SELECTOR = "css selector"
注意:该有的空格不能少,在csv中填写的定位方式也得按照这个来
读取文件脚本如下:
def test_addnote(self):
# 读取关键字驱动测试用例文件
file = open('keyframe.csv', 'r')
table = csv.reader(file)
header = next(table) # 跳过第一行
for row in table:
# print(row[3])
if row[6] == 'click':
self.driver.find_element(str(row[4]), str(row[5])).click()
elif row[6] == 'send_keys':
self.driver.find_element(str(row[4]), str(row[5])).send_keys(str(row[7]))
示例是使用的模拟器上有道云app添加笔记的功能,完整代码如下:
# 导入Appium类库
from appium.webdriver.webdriver import WebDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import csv
class yd_addnote():
# 使用初始化方法设置测试参数
def __init__(self):
self.caps = {
'automationName': 'UiAutomator2',
'platformName': 'Android',
'platformVersion': '6.0',
'deviceName': '192.168.23.101:5555',
'appPackage': 'com.youdao.note',
'appActivity': '.activity2.MainActivity'}
self.driver = WebDriver('http://127.0.0.1:4723/wd/hub', self.caps)
self.driver.implicitly_wait(10)
# 进入有道云
el = WebDriverWait(self.driver, 10).until(
lambda x: x.find_element(By.ID, 'com.android.packageinstaller:id/permission_allow_button'))
if el:
# 点击同意按钮
self.driver.find_element(By.ID, 'com.android.packageinstaller:id/permission_allow_button').click()
def test_addnote(self):
# 读取关键字驱动测试用例文件
file = open('keyframe.csv', 'r')
table = csv.reader(file)
header = next(table) # 跳过第一行
for row in table:
# print(row[3])
if row[6] == 'click':
self.driver.find_element(str(row[4]), str(row[5])).click()
elif row[6] == 'send_keys':
self.driver.find_element(str(row[4]), str(row[5])).send_keys(str(row[7]))
if __name__ == '__main__':
addnote = yd_addnote()
addnote.test_addnote()
版权声明
本文为[BetterFate!]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_42297382/article/details/124351466
边栏推荐
- [WPF binding 3] listview basic binding and data template binding
- Devexpress GridView add select all columns
- 92. Reverse linked list II byte skipping high frequency question
- Manually implement call, apply and bind functions
- C dapper basically uses addition, deletion, modification and query transactions, etc
- Router object, route object, declarative navigation, programmed navigation
- Detailed explanation of C webpai route
- Double pointer advanced -- leetcode title -- container with the most water
- MySQL进阶之索引【分类,性能分析,使用,设计原则】
- ASP. Net core JWT certification
猜你喜欢
STM32 entry development board choose wildfire or punctual atom?
[WPF binding 3] listview basic binding and data template binding
958. 二叉树的完全性检验
Qt 修改UI没有生效
超分之TDAN
Deep understanding of control inversion and dependency injection
ASP. Net core dependency injection service life cycle
常用SQL语句总结
快时钟同步慢时钟域下的异步控制信号slow clk to fast clk
1217_使用SCons生成目标文件
随机推荐
Node template engine (EJS, art template)
超分之TDAN
ECMAScript history
基于51单片机红外无线通讯仿真
470. Rand10() is implemented with rand7()
ASP. NET CORE3. 1. Solution to login failure after identity registers users
Simulation of infrared wireless communication based on 51 single chip microcomputer
快时钟同步慢时钟域下的异步控制信号slow clk to fast clk
剑指 Offer 03. 数组中重复的数字
Generating access keys using JSON webtoken
Entity Framework core captures database changes
古代埃及希腊,数学用的什么进制
41. The first missing positive number
C语言函数详解
386. 字典序排数(中等)-迭代-全排列
440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题
How to manually implement the mechanism of triggering garbage collection in node
[binary number] maximum depth of binary tree + maximum depth of n-ary tree
[ES6] promise related (event loop, macro / micro task, promise, await / await)
flink 学习(十二)Allowed Lateness和 Side Output