东莞商务网站建设/免费个人网站服务器
一、什么是 Robot Framework?
1. Robot Framework 的历史由来
Robot Framework是一种通用的自动化测试框架,最早由Pekka Klärck在2005年开发,并由Nokia Networks作为内部工具使用。后来,该项目以开源形式发布,并得到了广泛的社区支持和贡献。
2.官方介绍:
Robot Framework is a generic open source automation framework. It can be used for test automation and robotic process automation (RPA).
Robot Framework 是一个通用的开源自动化框架。它可用于测试自动化和机器人流程自动化 (RPA)。
Robot Framework is supported by Robot Framework Foundation. Many industry-leading companies use the tool in their software development.
Robot Framework 由 Robot Framework Foundation 提供支持。许多行业领先的公司在其软件开发中使用该工具。
Robot Framework is open and extensible. Robot Framework can be integrated with virtually any other tool to create powerful and flexible automation solutions. Robot Framework is free to use without licensing costs.
机器人框架是开放且可扩展的。Robot Framework几乎可以与任何其他工具集成,以创建强大而灵活的自动化解决方案。Robot Framework 可免费使用,无需许可费用。
Robot Framework has an easy syntax, utilizing human-readable keywords. Its capabilities can be extended by libraries implemented with Python, Java or many other programming languages. Robot Framework has a rich ecosystem around it, consisting of libraries and tools that are developed as separate projects.
Robot Framework 具有简单的语法,使用人类可读的关键字。它的功能可以通过使用 Python、Java 或许多其他编程语言实现的库来扩展。Robot Framework 拥有丰富的生态系统,由作为独立项目开发的库和工具组成。
3. 基本语法
- 测试用例以
*** Test Cases ***
开头,后跟一个或多个测试用例。 - 关键字定义以
*** Keywords ***
开头,后跟一个或多个关键字定义。 - 测试用例和关键字定义使用缩进来表示层次结构。
- 关键字和关键字参数之间使用制表符或多个空格分隔。
4. Code is worth a thousand words代码胜过千言万语
简单示例
此示例包含用户登录的单个测试用例。它使用模拟的后端 API 进行用户管理。该测试套件TestSuite.robot包含两个测试用例“使用密码登录用户”和“使用错误密码拒绝登录”。此测试用例从资源文件 keywords.resource 调用关键字。
TestSuite.robot:
*** Settings ***
Documentation A test suite for valid login.
...
... Keywords are imported from the resource file
Resource keywords.resource
Default Tags positive*** Test Cases ***
Login User with PasswordConnect to ServerLogin User ironman 1234567890Verify Valid Login Tony Stark[Teardown] Close Server ConnectionDenied Login with Wrong Password[Tags] negativeConnect to ServerRun Keyword And Expect Error *Invalid Password Login User ironman 123Verify Unauthorised Access[Teardown] Close Server Connection
Resource File 资源文件
keywords.resource 包含关键字定义。资源文件还使用库 CustomLibrary.py 中基于 python 的关键字来实现更专业的功能。存在无数社区制作的库,它们以各种方式扩展了机器人框架!
keywords.resource:
*** Settings ***
Documentation This is a resource file, that can contain variables and keywords.
... Keywords defined here can be used where this Keywords.resource in loaded.
Library CustomLibrary.py*** Keywords ***
Connect to ServerConnect fe80::aede:48ff:fe00:1122Close Server ConnectionDisconnectLogin User[Arguments] ${login} ${password}Set Login Name ${login}Set Password ${password}Execute LoginVerify Valid Login[Arguments] ${exp_full_name}${version}= Get Server VersionShould Not Be Empty ${version}${name}= Get User NameShould Be Equal ${name} ${exp_full_name}Verify Unauthorised AccessRun Keyword And Expect Error PermissionError* Get Server VersionLogin Admin[Documentation] 'Login Admin' is a Keyword.... It calls 'Login User' from 'CustomLibrary.py'Login User admin @RBTFRMWRK@Verify Valid Login Administrator
CustomLibrary.py:
from TestObject import TestObject
from robot.api.logger import info, debug, trace, consoleclass CustomLibrary:'''This is a user written keyword library.These libraries can be pretty handy for more complex tasks an typicallymore efficiant to implement compare to Resource files.However, they are less simple in syntax and less transparent in test protocols.The TestObject object (t) has the following public functions:class TestObject:def authenticate(self, login: str, password: str) -> str: ...def logout(self, token): ...def get_version(self, token) -> str: ...def get_user_id(self, token, login) -> str: ...def get_user_name(self, token, user_id) -> str: ...def get_user(self, token, user_id=None) -> Dict[str, str]: ...def get_user_all(self, token) -> List[Dict[str, str]]: ...def delete_user(self, token, userid): ...def get_logout(self, token): ...def put_user_password(self, token, new_password, user_id=None): ...def put_user_name(self, token, name, user_id=None): ...def put_user_right(self, token, right, user_id): ...def post_new_user(self, token, name, login) -> str: ...'''ROBOT_LIBRARY_SCOPE = 'SUITE'def __init__(self) -> None:self._session = Noneself.login = ''self.password = ''self._connection: TestObject = Nonedef connect(self, ip):self._connection = TestObject(ip)def disconnect(self):self._connection = None@propertydef connection(self):if not self._connection:raise SystemError('No Connection established! Connect to server first!')return self._connection@propertydef session(self):if self._session is None:raise PermissionError('No valid user session. Authenticate first!')return self._sessiondef set_login_name(self, login):'''Sets the users login name and stores it for authentication.'''self.login = logininfo(f'User login set to: {login}')def set_password(self, password):'''Sets the users login name and stores it for authentication.'''self.password = passwordinfo(f'Password set.')def execute_login(self):'''Triggers the authentication process at the backend and stores the session token.'''self._session = self.connection.authenticate(self.login, self.password)if self.session:info(f'User session successfully set.')debug(f'Session token is: {self.session}')self.login = self.password = ''def login_user(self, login, password) -> None:'''`Login User` authenticates a user to the backend.The session will be stored during this test suite.'''self._session = self.connection.authenticate(login, password)def logout_user(self):'''Logs out the current user.'''self.connection.logout(self.session)def create_new_user(self, name, login, password, right):'''Creates a new user with the give data.'''user_id = self.connection.post_new_user(self.session, name, login)self.connection.put_user_password(self.session, password, user_id=user_id)self.connection.put_user_right(self.session, right, user_id)def change_own_password(self, new_password, old_password):'''Changes the own password given the new and current one.'''self.connection.put_user_password(self.session, new_password, old_password)def change_users_password(self, login, new_password):'''Changes the password of a user by its name.Requires Admin priviliges!'''user_id = self.get_user_id(login)self.connection.put_user_password(self.session, new_password, user_id=user_id)def get_all_users(self):'''`Get All Users` does return a list of user-dictionaries.A user dictionary has the keys `name`, `login`, `right` and `active`.This keyword need Admin privileges.Example:`{'name': 'Peter Parker', 'login': 'spider', 'right': 'user', 'active': True}`'''return self.connection.get_user_all(self.session)def get_user_details(self, user_id=None):'''Returs the user details of the given user_id or if None the own user data.'''return self.connection.get_user(self.session, user_id)def get_user_id(self, login):'''Returns the user_id based on login.'''return self.connection.get_user_id(self.session, login)def get_username(self, user_id=None):'''Returns the users full name of the given user_id or if None the own user data.'''return self.connection.get_user_name(self.session, user_id)def get_server_version(self):return self.connection.get_version(self.session)
二、为什么选择 Robot Framework
Robot Framework支持插件化的架构,可以使用许多内置库和第三方库来扩展功能,例如SeleniumLibrary用于Web自动化测试,RequestsLibrary用于API测试等。
1. Robot Framework 的常见用法
Robot Framework可用于各种自动化测试任务,包括:
- Web应用测试
- API测试
- 数据库测试
- 移动应用测试
- 自动化任务和流程
- 持续集成和部署
2. 常见关键字库
Robot Framework有广泛的关键字库可供使用,以下是一些常见的关键字库:
- SeleniumLibrary:用于Web应用测试,包括页面操作、表单填写、页面验证等。
- RequestsLibrary:用于发送HTTP请求,进行API测试。
- DatabaseLibrary:用于数据库测试,支持各种数据库操作。
- SSHLibrary:用于通过SSH执行命令和操作远程服务器。
- ExcelLibrary:用于读写Excel文件。
- DateTimeLibrary:用于日期和时间相关操作。
3. 技术架构和原理
Robot Framework的技术架构基于关键字驱动的测试方法。它使用Python语言编写,通过解析测试用例文件和执行测试步骤来实现自动化测试。
Robot Framework的核心原理如下:
- 测试用例文件(通常使用
.robot
扩展名)包含测试用例、关键字定义和设置。 - 测试执行器(test runner)读取并解析测试用例文件。
- 测试执行器调用相应的关键字库(如SeleniumLibrary、RequestsLibrary等)执行测试步骤。
- 关键字库提供了一组关键字(如打开浏览器、点击按钮等)来操作被测试的系统。
- 执行结果被记录下来,并生成报告和日志文件。
三、怎么使用 Robot Framework
1. Robot Framework的安装方法
1. 安装Python
Robot Framework是基于Python的,所以首先需要安装Python。你可以从Python官方网站(https://www.python.org)下载适合你操作系统的Python安装程序,并按照官方指南进行安装。
2. 安装Robot Framework
一旦Python安装完成,你可以使用Python的包管理工具pip来安装Robot Framework。打开终端或命令提示符窗口,并执行以下命令:
pip install robotframework
这将下载并安装最新版本的Robot Framework及其依赖项。
3. 安装额外的关键字库
根据你的测试需求,你可能需要安装额外的关键字库。例如,如果你需要进行Web应用测试,可以安装SeleniumLibrary。以安装SeleniumLibrary为例,执行以下命令:
pip install robotframework-seleniumlibrary
类似地,你可以使用pip命令安装其他关键字库,具体取决于你的需求。
4. 验证安装
安装完成后,你可以验证Robot Framework是否成功安装。在终端或命令提示符窗口中执行以下命令:
robot --version
如果成功安装,它将显示安装的Robot Framework的版本号。
2. 自动化测试用例常见实例代码
示例1:Web应用测试
*** Settings ***
Library SeleniumLibrary*** Test Cases ***
Open Browser and Verify TitleOpen Browser https://www.example.com chromeTitle Should Be Example DomainClose Browser
示例2:API测试
*** Settings ***
Library RequestsLibrary*** Test Cases ***
Get User DetailsCreate Session Example API https://api.example.com${response} Get Request Example API /users/123Should Be Equal As Strings ${response.status_code} 200${user_details} Set Variable ${response.json()}Log ${user_details}Delete All Sessions
示例3:数据库测试
*** Settings ***
Library DatabaseLibrary
Library Collections*** Test Cases ***
Verify User in DatabaseConnect To Database pymysql mydatabase myusername mypassword@{query_result} Query SELECT * FROM users WHERE id = '123'Should Contain ${query_result} username=JohnDisconnect From Database
示例4:SSH操作
*** Settings ***
Library SSHLibrary*** Test Cases ***
Execute Command on Remote ServerOpen Connection 192.168.1.100 username=myusername password=mypassword${output} Execute Command ls /path/to/directoryShould Contain ${output} myfile.txtClose Connection
示例5:Excel操作
*** Settings ***
Library ExcelLibrary*** Test Cases ***
Read Data From ExcelOpen Excel path/to/excel/file.xlsx${cell_value} Read Cell Data By Name Sheet1 A1Log ${cell_value}Close Excel
四、相关链接
- Robot Framework官方网站
- Robot Framework用户指南
- Robot Framework论坛
- Robot Framework Github
RobotFramework基金会成员
相关文章:

通用开源自动化测试框架 - Robot Framework
一、什么是 Robot Framework? 1. Robot Framework 的历史由来 Robot Framework是一种通用的自动化测试框架,最早由Pekka Klrck在2005年开发,并由Nokia Networks作为内部工具使用。后来,该项目以开源形式发布,并得到了…...

css position属性与js滚动
“视口”就是浏览器窗口中实际显示文档内容的区域,不包含浏览器的“外框”,如菜单、工具条和标签。文档则是指整个网页。 1 css 的position static 正常定位,是元素position属性的默认值,元素遵循常规流。 relative 相对定位&…...

python内置模块hashlib对于字符串的加密解密加盐
hash是一类算法而hashlib模块是Python的一个内置模块,主要功能是使用对应的hash算法,加密二进制内容解密二进制内容 常见的hash算法有md5、sha1,sha256, sha512等 特点 1.内容敏感,那怕一个很小的字符发生改变都很明显 2.不可逆,不能逆向求值…...

获取客户端请求IP及IP所属城市
添加pom依赖 <dependency> <groupId>org.lionsoul</groupId> <artifactId>ip2region</artifactId> <version>2.6.5</version> </dependency> public class IpUtil { private…...

【洛谷 P1106】删数问题 题解(贪心+字符串)
删数问题 题目描述 键盘输入一个高精度的正整数 N N N(不超过 250 250 250 位),去掉其中任意 k k k 个数字后剩下的数字按原左右次序将组成一个新的非负整数。编程对给定的 N N N 和 k k k,寻找一种方案使得剩下的数字组成…...

【Python · PyTorch】线性代数 微积分
本文采用Python及PyTorch版本如下: Python:3.9.0 PyTorch:2.0.1cpu 本文为博主自用知识点提纲,无过于具体介绍,详细内容请参考其他文章。 线性代数 & 微积分 1. 线性代数1.1 基础1.1.1 标量1.1.2 向量长度&…...

建模和图表工具:Software Ideas Modeler Crack
用于图表、软件设计和分析的 CASE 工具 Software Ideas Modeler 是一款智能CASE 工具和 图表软件,支持 UML、SysML、ERD、BPMN、ArchiMate、流程图、用户故事、线框图。 提升用户体验和人工智能集成 - Software Ideas Modeler 14.05 最近发布的 14.05 版本带来了一…...

Android开发,车载通讯应用——binder通讯原理解析
Binder简单理解 简单来说,Binder 就是用来Client 端和 Server 端通信的。并且 Client 端和 Server 端 可以在一个进程也可以不在同一个进程,Client 可以向 Server 端发起远程调用,也可以向Server传输数据(当作函数参数来传&#…...

[算法]求n!在m进制下末尾有多少个0
参考链接:求n!在m进制下末尾0的个数_.!零n,,m-CSDN博客 我们这里和参考链接不同 使用结构体去存储每个因数的信息 然后使用变量index作为索引,其最终值为因数的个数 具体原理: 例子1:求9!在10进制下的…...

mysql之用户管理、权限管理、密码管理
用户管理 创建用户create user 杨20.0.0.13 identified by 123; 用户重命名rename user 杨20.0.0.13 to yang20.0.0.13; 删除用户drop user 杨20.0.0.13; 权限管理 查看用户权限show grants for 杨20.0.0.13; 赋予用户权限grant all privileges on *.* to 杨localhost id…...

图情档核心期刊 | 北大核心、CSSCI、CSCD
中文核心期刊要目总览(A Guide to the Core Journal of China, 简称北大核心): 主办单位:北京大学图书馆更新频率:北大核心在2008年之前每4年更新研究和编制出版一次,2008年之后,改为…...

Mac上具好用的屏幕录像工具(Omi录屏专家)Screen Recorder By Omi Mac 下载安装详细教程
Omi 录屏专家 是 Mac 上的一款出色的录音工具,它让您能够在Mac电脑上轻松录制和保存高质量音频。这款应用拥有简单直观的操作界面,无论我们水平如何,都可以轻松捕捉录制卓越的音质和录像视频。 该版本的 Omi 安装后可以直接支持最高 4K 60帧…...

牛客网刷题-(8)
🌈write in front🌈 🧸大家好,我是Aileen🧸.希望你看完之后,能对你有所帮助,不足请指正!共同学习交流. 🆔本文由Aileen_0v0🧸 原创 CSDN首发🐒 如…...

oracle 重启步骤及踩坑经验
oracle 重启步骤及踩坑经验 标准重启步骤 切换到oracle用户 su - oracle关闭监听 lsnrctl stop杀掉oracle有关进程 ps -ef|grep $ORACLE_SID|grep -v ora_|grep LOCALNO|awk {print $2}|xargs kill -9#查询pid ps -ef|grep $ORACLE_SID|grep -v ora_|grep LOCALNO|awk {p…...

处理mysql数据量大查询缓慢问题(最少百万才有差别)
我建了两个表,一个售后单表,一个售后商品明细表,都是五十个字段。 select * FROM (select id, as_id, as_date, outer_as_id, so_id, type, created, modified, status, status_name, shop_status, shop_status_name, remark, question_type,…...

element-plus走马灯不显示
问题描述 依赖正确,代码用法正确,但是element-plu走马灯就是不显示!! <div class"content"><el-carousel height"150px" width"200px"><el-carousel-item v-for"item in 4&qu…...

【精】UML及软件管理工具汇总
目录 1 老七工具(规划质量) 1.1 因果图(鱼骨图、石川图) 1.2 控制图 1.3 流程图:也称过程图 1.4 核查表:又称计数表 1.5 直方图 1.6 帕累托图 1.7 散点图…...

【uniapp+vue3】scroll-view实现纵向自动滚动及swiper实现纵向自动滚动
scroll-view本身不支持自动滚动,通过scroll-top属性控制滚动,但是不可以循环滚动 <scroll-view class"notice-bar" scroll-y"true" ref"scrollViewRef" :scroll-top"data.scrollViewTop"scroll-with-animati…...

this.refs[‘tagInput‘].refs.input.focus()和this.$refs[‘tagInput‘].focus()区别
this.$refs[tagInput].$refs.input.focus()和this.$refs[tagInput].focus()两者之间的选择取决于你的组件结构和如何访问DOM元素。 1.this.$refs[tagInput].$refs.input.focus(): 2.这种语法假设你的this.$refs[tagInput]是一个组件实例,并且这个组件实例有一个名为…...

电脑硬件坏了,如何维修?
在电子设备日益普及的今天,电脑已成为很多人生活和工作中不可或缺的工具,然而在使用过程中很容易遇见电脑故障之类的问题,这些问题十有八九来自硬件,那么针对电脑硬件问题,该如何维修? 一般来说,…...

elementplus日期时间选择器组件显示很窄
问题描述 似乎是elementplus原生组件的宽度是和父组件相关的 只要父组件很窄就会让弹窗也很窄,但其实两者的宽度不必有这种限制 解决思路 打开控制条查看元素位置以及css样式的class名 发现类名为el-picker-panel__body 尝试重构 css内写样式 .el-picker-pane…...

第三方软件测评选择远程测试好还是现场测试好?
如今许多软件企业在软件开发过程完成之后,会将软件测试工作交由第三方软件测评机构来进行,那么做第三方软件测试时,远程测试和现场测试哪个更好呢?我想这是许多软件企业都十分关注的问题,今天卓码软件测评小编将对以上问题作出简…...

HTTPS协议:保障网络安全的加密通信协议
在当今数字化时代,网络安全问题备受关注。为了保护用户的隐私和数据安全,HTTPS协议应运而生。本文将介绍HTTPS协议的定义、工作原理以及其在网络通信中的重要性。 一、HTTPS协议的定义 HTTPS(Hypertext Transfer Protocol Secure)…...

C++设计模式_21_Iterator 迭代器(理解;面向对象的迭代器已过时;C++中使用泛型编程的方式实现)
Iterator 迭代器也是属于“数据结构”模式。GoF中面向对象的迭代器已经过时,C中目前使用泛型编程的方式实现,其他语言还在使用面向对象的迭代器。 文章目录 1. 动机(Motivation)2. 模式定义3. Iterator 迭代器代码分析4. 面向对象的迭代器与泛型编程实现…...

有一个 3*4 的矩阵,找出其中值最大的元素,及其行列号
1解题思路: 首先学会输入二维数组;然后知道如何比较求最大值;最后就是格式问题; 2代码: #include<stdio.h> int main() {int a[3][4];int i,j,max,row,line;for(i0;i<3;i){printf("请输入二维数组\n&…...

磁盘的命令
目录 1- 磁盘空间命令1.1 df1.2 du只想查看目录的权限 加 -d 参数 1- 磁盘空间命令 1.1 df 全称 disk free 快速获取磁盘被占用了多少空间, 目前还剩下所少空间 常用命令df -hdf 是从总体上统计系统各磁盘的占用情况,不能统计具体的文件夹或文件的大小 1.2 du 全称 disk u…...

一张图讲清楚业务稳定性要如何做:SRE体系化稳定性方案
概述:作为一个SRE、运维工程师,当我们在治理系统稳定性时,方法有很多,但往往无从下手。本文以一张逻辑图的形式,为读者提供治理稳定性的体系化思路。 先上图: 1、治理目标 我们做稳定性的目标,…...

安卓端GB28181设备接入模块如何实现实时位置订阅(MobilePosition)
技术背景 实时位置(MobilePosition)订阅和上报,对GB28281设备接入终端尤其重要,如移动单兵设备、执法记录仪、智能安全帽、车载终端等,Android国标接入设备通过获取到实时经纬度信息,按照一定的间隔上报到…...

11.与JavaScript深入交流-[js一篇通]
文章目录 1.变量的使用1.1基本用法1.2理解 动态类型 2.基本数据类型2.1number 数字类型2.1.1数字进制表示2.1.2特殊的数字值 2.2string 字符串类型2.2.1基本规则2.2.2转义字符2.2.3求长度2.2.4字符串拼接 2.3boolean 布尔类型2.4undefined 未定义数据类型2.5null 空值类型 3.运…...

Ubuntu 搭建 DHCP ivp6 server 步骤
Ubuntu 搭建 DHCP ivp6 server 步骤 安装 DHCP server安装 radvd(实现局域网路由功能)测试运行 安装 DHCP server apt 安装 isc-dhcp-server sudo apt-get install isc-dhcp-server修改配置文件 /etc/dhcp/dhcpd6.conf 内容如下: lease-time 7200; lo…...