当前位置:网站首页>RobotFramework 之 数据驱动
RobotFramework 之 数据驱动
2022-08-09 13:06:00 【沉觞流年】
RobotFramework 之 数据驱动
RF数据驱动
用例逻辑相同,每次输入的数据不同,并且数据量很大的时候,这时候就要使用到数据驱动。
比如测试输入框的内容,页面上有很多输入框,在输入框中要输入很多次数据进行验证,负数、0、小数、整数、中文、英文、特殊字符及组合输入。
总不能说每个输入框、每次输入都写一个测试用例进行验证,通过复制粘贴去修改内容,多麻烦。这时候用上数据驱动,就会省事很多
在RF中,通过使用 [template]
用户关键字自发实现数据驱动
没有这种类型的例子进行很好的说明,依旧使用163邮箱登录进行举例验证
common.robot
*** Settings ***
Library SeleniumLibrary
*** Keywords ***
登录网易邮箱
[Arguments] ${
账号} ${
密码}
# 打开chrome浏览器访问163邮箱
open browser https://mail.163.com/ chrome
sleep 5
maximize browser window
# 切换到iframe
select frame xpath=//iframe[contains(@id,'iframe')]
# 用户名输入框中输入 用户名
sleep 2
input text xpath=//*[@name="email"] ${
账号}
sleep 2
# 密码输入框中输入 密码
input text xpath=//*[@name="password"] ${
密码}
sleep 2
# 点击登录按钮
click element xpath=//*[@id="dologin"]
sleep 10
关闭浏览器
close browser
[Template]
关键字后的内容是定义的用户关键字
,语法要求是后面接关键字
而此时用例的主体变成了要传递的参数的内容,对应的是${账号}
、${密码}
(编辑器会识别不了该语法,因为第一个参数不是关键字,会报红,但运行是不会报错的)
test.robot
*** Settings ***
Library SeleniumLibrary
Resource common.robot
*** Test Cases ***
网易邮箱
[Template] 登录网易邮箱
用户名1 密码1
用户名2 密码2
注意,此时用例主体就不能再有其他关键字内容了,因为都变成了默认对应的参数${账号}
、${密码}
,如果还有其他关键字内容,会被当成是对应的参数进行传递,或者参数不对应,产生报错
test.robot
*** Settings ***
Library SeleniumLibrary
Resource common.robot
*** Test Cases ***
网易邮箱
[Template] 登录网易邮箱
用户名1 密码1
用户名2 密码2
sleep 10
log 账号密码输入正确 登录成功
此时 sleep
和 log
都不被当成关键字了,而是当成是参数传递,因为 log
一行相当于有3个参数,所以会产生报错
RF中的数据驱动没有python中来的方便,RF中没有关键字去读取excel中的数据,如果要在RF中使用比较复杂的数据驱动功能,还是推荐写成python模块,然后再进行引用
边栏推荐
- Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres
- Come and throw eggs.
- WSA toolkit installed app store tip doesn't work how to solve?
- Record the system calls and C library functions used in this project-2
- Uni - app - uview Swiper shuffling figure component, click on the links to jump (click to get the item after the row data, remove data operation)
- 陈强教授《机器学习及R应用》课程 第十四章作业
- 时间序列分析课程实验报告
- NC84 完全二叉树结点数
- 绘制混合密度函数图以及添加分位数线
- X264性能优化
猜你喜欢
群组行动控制--自动队列化实现策略
gin的中间件和路由分组
WSA toolkit installed app store tip doesn't work how to solve?
GIN Bind mode to get parameters and form validation
Unicom network management protocol block diagram
问题系列-如何修改或更新localhost里的值
基于 R 语言的判别分析介绍与实践 LDA和QDA
微服务+微信小程序实现社区服务
蓝桥杯线上模拟赛——Flex 经典骰子布局
Unity3d_API_Gyroscope 陀螺仪的接口
随机推荐
正则表达式-re模块
RTSP协议的实现
JZ7 重建二叉树
Rmarkdown教程
32位机器和64位机器基本数据类型长度
蓝桥历届真题-蛇形填数
现在40系显卡都快出来了,为何1060型号的显卡还有这么多人用?
Process/Thread related in Sandbox - 1
行程和用户[阅读理解法]
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 13 Assignment
JS轮播图实现
LeetCode 37.解数独
GIN Bind mode to get parameters and form validation
offset、client、scroll、window.pageYOffset比较
Q_07 词汇表
error Trailing spaces not allowed no-trailing-spaces 9:14 error Unexpected trailing comma
5G China unicom general exception handling
自己做了个nodejs+epxress+mysql的小项目,怎么才能让别人通过互联网访问呢?
Dry+Bean+Dataset R语言数据分析,报告英文
Draw a histogram with plot_hist_numeric()