当前位置:网站首页>RobotFramework 之 资源文件
RobotFramework 之 资源文件
2022-08-09 13:06:00 【沉觞流年】
RobotFramework 之 资源文件
资源文件
资源(Resource):
用户关键字的集合。用来对用户关键字进行管理。
类比python中编写自己的类。
举例: 使用用户关键字方式登录163邮箱
登录163邮箱.robot
*** Settings ***
Library SeleniumLibrary
*** Keywords ***
登录网易邮箱
# 打开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
*** Test Cases ***
网易邮箱
登录网易邮箱
可以发现,在该文件中的测试用例中调用 登录网易邮箱关键字,执行了登录网易邮箱的操作。
新建一个test.robot文件
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
网易邮箱2
登录网易邮箱
执行test.robot文件,报错,找不到 登录网易邮箱关键字
在测试套件文件中定义关键字,只能在本测试套件中有效,无法共享给其他测试套件使用
这时候,就需要引入 资源文件 这一概念了:
资源文件 其实就是RF层面的库文件(不能包含测试用例表),里面的内容为共享的变量和关键字
导入资源文件
新建一个 common.robot 文件
common.robot
*** Settings ***
Library SeleniumLibrary
*** Keywords ***
登录网易邮箱
# 打开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
通过在测试用例文件的Settings表中Resource common.robot导入资源文件,即可使用 资源文件 里共享的变量和关键字的内容
test.robot
*** Settings ***
Library SeleniumLibrary
Resource common.robot
*** Test Cases ***
网易邮箱2
登录网易邮箱
log to console 这里是用例主体部分
关闭浏览器
此时执行test.robot文件,就不会产生报错了
资源文件与用例前置、后置结合使用
在大多数时候,登录会变成测试套件的用例前置的内容,关闭浏览器是用例后置的内容,所以,通常在测试套件中,会这样来写
test.robot
*** Settings ***
Library SeleniumLibrary
Resource common.robot
Suite Setup 登录网易邮箱
Suite Teardown 关闭浏览器
*** Test Cases ***
用例1
log to console 这里是用例主体部分
用例2
log to console 这里是用例主体部分
使用 套件级别的 Suite Setup,将登录网易邮箱关键字作为前置内容,将关闭浏览器关键字作为后置内容,执行用例1和用例2前就已执行登录操作,用例1和用例2执行结束,关闭浏览器
资源文件的作用是对用户关键字进行管理,将重复的内容提取出来,简化测试用例中的操作步骤
边栏推荐
猜你喜欢

How to solve the 0x80070005 error when the computer is reinstalled and the system is restored

5G Unicom Network Management Design Ideas

Map mixed density function and quantile added line

IDEA Gradle 常遇问题(二)(持续更新)

蓝桥历届真题-跑步锻炼

jenkins api create custom pipeline

render解析

蓝桥历届真题-蛇形填数

关于做2D游戏时,Canvas边界显示在Game窗口的问题

19、学习MySQL 索引
随机推荐
搭建大型分布式服务(四)Docker搭建开发环境安装Mysql
gin的中间件和路由分组
缓存和数据库一致性问题
NC193 二叉树的前序遍历
FFmpeg多媒体文件处理(ffmpeg打印音视频Meta信息)
Process/Thread related in Sandbox - 1
uni-app - uview Swiper 轮播图组件点击跳转链接(点击后拿到 item 行数据, 取出数据做操作)
5G China unicom AP:B SMS ASCII Transcoding Requirements
剑指offer,剪绳子2
音频基础学习——声音的本质、术语与特性
Professor Chen Qiang "application in machine learning and R" course chapter 17
ArcEngine(十)创建矢量图层
How to reduce the size of desktop icons after the computer is reinstalled
GIN Bind模式获取参数和表单验证
Realization of RTSP Protocol
Q_06_01 Q#编程语言
群组行动控制--自动队列化实现策略
ARM board adds routing function
蓝桥历届真题-既约分数
剑指 Offer 57 - II. 和为s的连续正数序列(滑动窗口)