RobotFramework简介(架构+标准库)

简介: 这篇文章是我在学习Robot框架过程中所总结的,主要简单介绍了Robot Framework的基础架构和标准库知识。要想学好Robot并且少走弯路,了解这些基础知识我认为是很有必要的,因为它可以给你一个大致的入门思路和学习方向,让你不至于迷茫到底该从哪里下手学习RF。

这篇文章是我在学习Robot框架过程中所总结的,主要简单介绍了Robot Framework的基础架构和标准库知识。要想学好Robot并且少走弯路,了解这些基础知识我认为是很有必要的,因为它可以给你一个大致的入门思路和学习方向,让你不至于迷茫到底该从哪里下手学习RF。

RobotFramework 官网
PyPI
GitHub
Robot Framework User Guide

Intro

Robot Framework is a Python-based keyword-driven test automation framework for acceptance level testing and acceptance test-driven development (ATDD). It has an easy-to-use tabular syntax for creating test cases and its testing capabilities can be extended by test libraries implemented either with Python or Java. Users can also create new higher level keywords from existing ones using the same simple syntax that is used for creating test cases.

Robot Framework是一个基于Python并且是关键字驱动的开源自动化测试框架,主要用于验收级别测试和验收测试驱动开发(ATDD)。它有一个易于使用的表格语法,用于创建测试用例,它的测试功能可以通过用Python或Java实现的测试库来扩展。用户还可以使用与创建用例时相似的简单语法,来从现有的关键字中创建新的更高级别的关键字。

Why Robot Framework ?

Copy From Robot Framework User Guide

  • Enables easy-to-use tabular syntax for creating test cases in a uniform way;
    支持易于使用的表格语法,并以统一的方式创建测试用例;
  • Provides ability to create reusable higher-level keywords from the existing keywords;
    提供从已有的关键字来封装可重用的高级关键字的能力;
  • Provides easy-to-read result reports and logs in HTML format;
    结果报告和日志以HTML格式提供,简单易读;
  • Is platform and application independent;
    平台和应用程序相互独立;
  • Provides a simple library API for creating customized test libraries which can be implemented natively with either Python or Java ;
    提供一个简单的 API来定制测试库,可以用Python或Java实现;
  • Provides a command line interface and XML based output files for integration into existing build infrastructure (continuous integration systems);
    为集成到现有的持续集成系统(CI) 提供一个命令行接口和基于XML的输出文件;
  • Provides support for Selenium for web testing, Java GUI testing, running processes, Telnet, SSH, and so on;
    为web测试、Java GUI测试、运行流程、Telnet、SSH等提供支持;
  • Supports creating data-driven test cases;
    支持创建数据驱动的测试用例;
  • Has built-in support for variables, practical particularly for testing in different environments;
    有内置支持变量,支持在不同的环境中进行测试;
  • Provides tagging to categorize and select test cases to be executed;
    以tag进行标记分类测试用例和选择执行;
  • Enables easy integration with source control: test suites are just files and directories that can be versioned with the production code;
    易于和版本控制系统集成,测试套件是文件和目录,可以与代码一同进行版本控制;
  • Provides test-case and test-suite -level setup and teardown;
    提供测试用例和测试套件水平的 setup 和 teardown ;
  • The modular architecture supports creating tests even for applications with several diverse interfaces;
    模块化结构支持使用不同的接口来测试不同的应用;

Usage

Starting from Robot Framework 3.0, tests are executed from the command line using the robot script or by executing the robot module directly like python -m robot or jython -m robot. Older Robot Framework versions have Python interpreter specific pybot, jybot and ipybot scripts that still work but will be deprecated and removed in the future

目前Robot框架最新版本为3.0.4,从3.0版本开始,通过使用robot脚本或是执行robot模块,比如python -m robotjybot -m robot的方式来从命令行执行测试。旧版本的Robot框架有特定于Python解释器的pybot、jybot和ipybot脚本,这些脚本仍然可以工作,但将来会被弃用和删除。

img_af2b355083ad725ad1ca94c24949485a.png

三个脚本的内容如下:

#pybot.bat
@echo off
python -m robot.run %*

#robot.bat 
@echo off
c:\python36\python.exe -m robot.run %*

# rebot.bat
@echo off
c:\python36\python.exe -m robot.rebot %*

基础用法:robot [OPTINOS] [PATH],如:

robot tests.robot`
`robot --variable HOST:example.com --outputdir results path/to/tests/

此外,rebot工具可以组合结果和其他后处理输出:

rebot --name Example output1.xml output2.xml

运行robot --helprebot --help,可以获得关于命令行用法的更多信息。

RobotFramework 架构

Robot Framework is a generic, application and technology independent framework. It has a highly modular architecture illustrated in the diagram below.

机器人框架是一个通用的、应用和技术的独立框架。它有一个高度模块化的架构,如下图所示。


img_253c2800e920f38b8985f5addbcc4d1a.png
Robot Framework architecture

如果需要用一句话来形容下RobotFramework 可以做哪些事情的话,下面这句话或许很恰当:

The core framework does not know everything about the target under test,and the interactiuon with it is handled by test libraries.

RobotFramework 库介绍

RF的库分为标准库(standard library)和扩展库(external library)。
对于标准库,这些库是直接绑定在RF内的,在
..\Python27\Lib\site-packages\robot\libraries
下可以看到,无须再下载;而外部库,是需要根据个人需要,下载后再安装导入才能使用的。 对于标准库,又分两类,类似BuiltIn库是RF自动加载到内存的,安装后按下F5就能直接使用,不需要再次import,而XML库需要再次import才能正常使用。因为BuiltIn Library 提供了很多常用的关键字,比如Sleep, Log, Evaluate等,所以RF就把这个常用的库自动加载到了内存。

img_f31111a74316b80940bd8e26a67d877f.png
standard library

官网上标出的11个标准库在这里都能找到对应的.py文件。

img_dd2d09ba97c5bfe1982c63bd2ad3096c.png
image.png

不同的RF版本,相同的标准库之间也可能会有细微的差别,以下以 the latest version:v3.0.2 ,概括介绍下这几个标准库的作用。

Reference From Robot Framework documentation

  • BuiltIn : 自动导入,它包含一些非常常用的关键字,如Log、Set Variable、Evaluate、Sleep 、Comment、Should Be Equal...
  • Collections : 处理操作List 和 Dictionary;
  • DateTime : 支持创建和验证日期/时间值以及它们之间的计算;
  • Dialogs : 支持暂停测试执行并从用户那里获得输入;
  • OperatingSystem : 支持执行各种操作系统相关的任务;
  • Process : 支持系统中的执行进程;
  • Screenshot : 捕获和存储截图;
  • String : 处理操作字符串;
  • Telnet : 支持连接到Telnet 服务器上打开的连接执行命令;
  • XML : 验证和修改XML文档;
  • Remote : 部分远程库接口,它没有关键字.
    />>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    end.
相关文章
|
6月前
|
监控 负载均衡 测试技术
服务网格简介:探索现代微服务架构中的服务网格概念和价值
服务网格简介:探索现代微服务架构中的服务网格概念和价值
99 0
|
1月前
|
消息中间件 存储 SQL
Flume【基础知识 01】简介 + 基本架构及核心概念 + 架构模式 + Agent内部原理 + 配置格式(一篇即可入门Flume)
【2月更文挑战第18天】Flume【基础知识 01】简介 + 基本架构及核心概念 + 架构模式 + Agent内部原理 + 配置格式(一篇即可入门Flume)
447 0
|
1月前
|
分布式计算 API 数据处理
Flink【基础知识 01】(简介+核心架构+分层API+集群架构+应用场景+特点优势)(一篇即可大概了解flink)
【2月更文挑战第15天】Flink【基础知识 01】(简介+核心架构+分层API+集群架构+应用场景+特点优势)(一篇即可大概了解flink)
56 1
|
2月前
|
边缘计算 Kubernetes 物联网
大规模 IoT 边缘容器集群管理的几种架构 -0- 边缘容器及架构简介
大规模 IoT 边缘容器集群管理的几种架构 -0- 边缘容器及架构简介
|
2月前
|
存储 消息中间件 API
|
4月前
|
SQL 关系型数据库 MySQL
Presto【基础 01】简介+架构+数据源+数据模型+特点(一篇即可入门支持到PB字节的分布式SQL查询引擎Presto)
Presto【基础 01】简介+架构+数据源+数据模型+特点(一篇即可入门支持到PB字节的分布式SQL查询引擎Presto)
54 0
|
6月前
|
存储 运维 关系型数据库
直播预告 | PolarDB-PG架构简介及日常运维浅析
本次分享将先从架构、特性、开源等三个维度解读PolarDB-PG的整体架构。在大家对架构有一定深入理解后,将继续从备份恢复、存储层、计算层扩容、只读节点提升、高可用等五个维度,对PolarDB-PG的日常运维进行深入浅出的介绍,为“唯手熟尔”的运维打好理论基础。
|
7月前
|
存储 安全 API
orbeon form 的架构简介 - 如何访问用户通过 form 存储的数据
orbeon form 的架构简介 - 如何访问用户通过 form 存储的数据
51 0
|
7月前
|
SQL 前端开发 API
Django系列:Django简介与MTV架构体系概述
Django简介与MTV架构体系概述
87 0
|
7月前
|
存储 安全 调度
SAP Commerce Cloud 里的 Solr 架构简介
SAP Commerce Cloud 里的 Solr 架构简介
45 0