当前位置:网站首页>【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
边栏推荐
- Ouvrir des contrats à terme, ouvrir des comptes en nuage ou faire confiance aux logiciels des sociétés à terme?
- For the space occupation of the software, please refer to the installation directory
- Devexpress GridView add select all columns
- 2021长城杯WP
- Halo open source project learning (II): entity classes and data tables
- 209. 长度最小的子数组-滑动窗口
- Using quartz under. Net core -- a simple trigger of [7] operation and trigger
- 394. String decoding - auxiliary stack
- Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
- Manually implement call, apply and bind functions
猜你喜欢

JVM class loading mechanism

470. 用 Rand7() 实现 Rand10()
![Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers](/img/65/89473397da4217201eeee85aef3c10.png)
Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers

Clickhouse table engine

Learning record of uni app dark horse yougou project (Part 2)

双闭环直流调速系统matlab/simulink仿真

为什么有些人说单片机简单,我学起来这么吃力?

Allowed latency and side output

MySQL进阶之索引【分类,性能分析,使用,设计原则】

Matlab / Simulink simulation of double closed loop DC speed regulation system
随机推荐
394. String decoding - auxiliary stack
Matlab / Simulink simulation of double closed loop DC speed regulation system
索引:手把手教你索引从零基础到精通使用
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
[binary number] maximum depth of binary tree + maximum depth of n-ary tree
Construction of functions in C language programming
快时钟同步慢时钟域下的异步控制信号slow clk to fast clk
How does matlab draw the curve of known formula and how does excel draw the function curve image?
41. 缺失的第一个正数
STM32 entry development board choose wildfire or punctual atom?
PC电脑使用无线网卡连接上手机热点,为什么不能上网
Using quartz under. Net core -- preliminary understanding of [2] operations and triggers
Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers
flink 学习(十二)Allowed Lateness和 Side Output
MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
01 - get to know the advantages of sketch sketch
Websocket (basic)
239. Maximum value of sliding window (difficult) - one-way queue, large top heap - byte skipping high frequency problem
Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
Generating access keys using JSON webtoken