您可以捐助,支持我们的公益事业。

1元 10元 50元





认证码:  验证码,看不清楚?请点击刷新验证码 必填



  求知 文章 文库 Lib 视频 iPerson 课程 认证 咨询 工具 讲座 Model Center   Code  
会员   
   
 
     
   
 订阅
  捐助
Robot Framework基础入门
 
  3845  次浏览      17
 2018-3-29 
 

 

编辑推荐:

本文来自于csdn,Robot Framework是一个基于Python可扩展地关键字驱动的测试自动化框架.

使用Apache License 2.0,由Robot Framework Foundation开发和赞助。Robot Framework被广泛地使用在端到端地验收测试以及ATDD(acceptance-test-driven development )中,生态体系非常丰富,更详细的信息可以参看http://robotframework.org。本文将简单介绍如何安装Robot Framework以及运行第一个Hello World的例子。

为甚麽使用Robot Framework

有很多理由使得Robot Framework非常受欢迎,比如:

支持简单易用的表格型语法,使得可以用统一方式创建测试用例

提供可以复用既存的关键字的功能

提供HTML的简单易读的报表和日志结果文件

平台和应用相互独立

提供简单的Libary API,可以使用Ptyhon或者java进行实现

提供命令行接口也XML格式的输出文件,非常容易进行持续集成

支持Selenium,Java Gui测试,Telnet,SSH等

支持创建数据驱动的测试用例

变量的内建支持,尤其是不同测试环境下的测试

提供test case和test suite级别的setup和teardown

Robot架构

Robot是一个通用的测试框架,解耦做的很好,虽然很简单,整体的架构如下所示:

安装前提

因为Robot是基于Python进行开发的,使用Python2还是Python3是一个需要选择的问题,python2是在2010年发布的,目前稳定版本2.7.5,python2会支持到2020年,至于更多的区别,可以参看如下文章以决定你的选择。

项目 项目
Python2还是Python3 https://wiki.python.org/moin/Python2orPython3

因为没有考虑到会用到比较新的python的功能,本文的安装采用目前稳定的Python2。

[root@liumiaocn ~]# python --version
Python 2.7.5
[root@liumiaocn ~]#

安装PIP

robot的安装有很多方式,为了避免第一个HelloWorld花费太多时间,果断采取PIP直接安装的方式。

[root@liumiaocn ~]# yum install epel-release
Loaded plugins: fastestmirror
...
Installed:
epel-release.noarch 0:7-9

Complete!
[root@liumiaocn ~]#

[root@liumiaocn ~]# yum -y install python-pip
Loaded plugins: fastestmirror
...

Installed:
python2-pip.noarch 0:8.1.2-5.el7

Dependency Installed:
python-backports.x86_64 0:1.0-8.el7 python-backports-ssl_match_hostname.noarch 0:3.4.0.2-4.el7
python-setuptools.noarch 0:0.9.8-4.el7

Complete!
[root@liumiaocn ~]#

确认PIP版本

[root@liumiaocn ~]# pip --version
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
[root@liumiaocn ~]#

安装Robot Framework

[root@liumiaocn ~]# pip install robotframework
Collecting robotframework
Downloading robotframework-3.0.2.tar.gz (440kB)
100% |████████████████ ████████████████| 450kB 344kB/s
Installing collected packages: robotframework
Running setup.py install for robotframework ... done
Successfully installed robotframework-3.0.2
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@liumiaocn ~]#

确认Robot版本

[root@liumiaocn ~]# robot --version
Robot Framework 3.0.2 (Python 2.7.5 on linux2)
[root@liumiaocn ~]#
[root@liumiaocn ~]# rebot --version
Rebot 3.0.2 (Python 2.7.5 on linux2)
[root@liumiaocn ~]#
[root@liumiaocn ~]# pybot --version
Robot Framework 3.0.2 (Python 2.7.5 on linux2)
[root@liumiaocn ~]#

Robot测试脚本

准备就绪,可以开始创建第一个测试脚本了。第一个Helloworld的测试脚本如下所示:

[root@liumiaocn robot]# ls
helloworld.robot
[root@liumiaocn robot]# cat helloworld.robot
*** Settings ***
*** Variables ***
*** Test Cases ***
First test case
Begin web test
Second test case
End web test
*** Keywords ***
Begin web test
Log This is first test case
End web test
Log HelloWorld
[root@liumiaocn robot]#

熟悉关键字驱动测试的都很容易地看到这是做了两个关键字和两个测试用例。

执行脚本

使用robot helloworld.robot即可开始执行。

可以清楚地看到测试用例地执行情况以及它的输出。

执行结果

执行之后产生了三个结果文件:

日志文件

结果报表

注意日志文件和报表文件都是自动连接起来地,不要人为随意改变其相对目录。

输出文件

详细的输出信息,可以使用其进行更方便的持续集成。

<?xml version="1.0" encoding="UTF-8"?>
<robot generated="20170611 19:11:45.787" generator="Robot 3.0.2 (Python 2.7.5 on linux2)">
<suite source="/root/robot/helloworld.robot" id="s1" name="Helloworld">
<test id="s1-t1" name="First test case">
<kw name="Begin web test">
<kw name="Log" library="BuiltIn">
<doc>Logs the given message with the given level.</doc>
<arguments>
<arg>This is first test case</arg>
</arguments>
<msg timestamp="20170611 19:11:45.807" level="INFO">This is first test case</msg>
<status status="PASS" endtime="20170611 19:11:45.807" starttime="20170611 19:11:45.806"></status>
</kw>
<status status="PASS" endtime="20170611 19:11:45.807" starttime="20170611 19:11:45.806"></status>
</kw>
<status status="PASS" endtime="20170611 19:11:45.807" critical="yes" starttime="20170611 19:11:45.806"></status>
</test>
<test id="s1-t2" name="Second test case">
<kw name="End web test">
<kw name="Log" library="BuiltIn">
<doc>Logs the given message with the given level.</doc>
<arguments>
<arg>HelloWorld</arg>
</arguments>
<msg timestamp="20170611 19:11:45.808" level="INFO">HelloWorld</msg>
<status status="PASS" endtime="20170611 19:11:45.808" starttime="20170611 19:11:45.808"></status>
</kw>
<status status="PASS" endtime="20170611 19:11:45.808" starttime="20170611 19:11:45.807"></status>
</kw>
<status status="PASS" endtime="20170611 19:11:45.808" critical="yes" starttime="20170611 19:11:45.807"></status>
</test>
<status status="PASS" endtime="20170611 19:11:45.808" starttime="20170611 19:11:45.789"></status>
</suite>
<statistics>
<total>
<stat fail="0" pass="2">Critical Tests</stat>
<stat fail="0" pass="2">All Tests</stat>
</total>
<tag>
</tag>
<suite>
<stat fail="0" id="s1" name="Helloworld" pass="2">Helloworld</stat>
</suite>
</statistics>
<errors>
</errors>
</robot>

总结

本文简单介绍了Robot Framework的概要信息以及如何安装和执行第一个Robot的Helloworld的测试脚本,同时确认了其输出的结果。Robot的强大在这个测试脚本中完全无法得到体现,后续会慢慢展开Robot Framework的各种使用方法。

   
3845 次浏览       17
相关文章

微服务测试之单元测试
一篇图文带你了解白盒测试用例设计方法
全面的质量保障体系之回归测试策略
人工智能自动化测试探索
相关文档

自动化接口测试实践之路
jenkins持续集成测试
性能测试诊断分析与优化
性能测试实例
相关课程

持续集成测试最佳实践
自动化测试体系建设与最佳实践
测试架构的构建与应用实践
DevOps时代的测试技术与最佳实践