当前位置:网站首页>【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
边栏推荐
- Using quartz under. Net core -- job attributes and exceptions of [4] jobs and triggers
- STM32 entry development board choose wildfire or punctual atom?
- [binary number] maximum depth of binary tree + maximum depth of n-ary tree
- Change Oracle to MySQL
- C语言函数详解
- Indexes and views in MySQL
- Halo 开源项目学习(二):实体类与数据表
- PC uses wireless network card to connect to mobile phone hotspot. Why can't you surf the Internet
- Devexpress GridView add select all columns
- Entity Framework core captures database changes
猜你喜欢
440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
470. Rand10() is implemented with rand7()
MySQL进阶之索引【分类,性能分析,使用,设计原则】
超分之TDAN
Matlab / Simulink simulation of double closed loop DC speed regulation system
92. Reverse linked list II byte skipping high frequency question
2.Electron之HelloWorld
394. 字符串解码-辅助栈
STM32 entry development board choose wildfire or punctual atom?
随机推荐
Use of shell sed command
If you start from zero according to the frame
基于51单片机红外无线通讯仿真
Detailed explanation of C webpai route
干货 | 快速抽取缩略图是怎么练成的?
Perception of linear algebra 2
Collection of common SQL statements
958. 二叉树的完全性检验
Simulation of infrared wireless communication based on 51 single chip microcomputer
ECMAScript history
Using quartz under. Net core -- a simple trigger of [7] operation and trigger
Excel quickly and automatically fills the contents of a row on a blank cell
Generating access keys using JSON webtoken
tidb-server 的配置文件在哪里?
Using quartz under. Net core - [1] quick start
练习:求偶数和、阈值分割和求差( list 对象的两个基础小题)
Use of shell awk command
1217_ Generating target files using scons
Kubernetes 服务发现 监控Endpoints
Router object, route object, declarative navigation, programmed navigation