Robot Framework automated testing (1) --- the first script

Recently, Robot Framework is used for automation in tools, so I took the time to learn it.

 

=======Required Environment====================

Python:

https://www.python.org/

The RF framework is based on python  , so be sure to have a python environment.

 

Robot framework :

https://pypi.python.org/pypi/robotframework/2.8.5

  This is not explained, RF framework. Although when doing UI -based automation, it looks a lot like QTP , and I thought it was similar to QTP , there 's still a lot you can do to develop it carefully. Just like beginners of selenium  , they will mistakenly think that selenium  is selenium IDE .

 

wxPython:

http://www.wxpython.org/download.php

  Wxpython  is a very famous GUI library for python  , because RIDE  is developed based on this library, so this must be installed.

 

Robot framework-ride

https://pypi.python.org/pypi/robotframework-ride

  RIDE is a graphical interface software for creating, organizing, and running tests.

 

Robot framework-selenium2library:

https://pypi.python.org/pypi/robotframework-selenium2library/1.5.0

  RF-seleniumlibrary can be regarded as the RF version of the selenium  library, and selenium  ( webdriver ) can be considered as a set of web -based specifications ( API ), so RF  , appium  and other testing tools can locate and operate pages based on this API .

----------------------

It can be installed via python  's pip toolkit:

>pip install robotframework-selenium2library

 

If you come into contact with the above things for the first time, I feel that there are a lot of things installed. If you have known python  or selenium before , you will not have this feeling.

 ================================================

  在你安装好RF-ride之后,桌面就会生成一个RIDE图标。双击启动,界面如下:

  

 下面我们就一步一步的创建第一条用例,至于细节不多解释,只是对RF框架写用例有个感性的认识。

 

 

创建测试项目                                          

 选择菜单栏file----->new Project

Name 输入项目名称。

Type 选择Directory

 

 

创建测试套件                                            

  右键点击“测试项目”选择new Suite 选项

Name 输入项目名称。

Type 选择File

 

 

创建测试用例                                                  

     右键点击“测试项目”选择new Test Case 

用例只需要输入用例name ,点击OK即可。

 

 

导入selenium2library库                         

      因为RF框架编写基于web 的测试用例,所以,我们需要selenium 的库支持。所以,我们在使用的过程中需要加载selenium2library库。

在“测试套件”的Edit标签页,点击“Library”按钮,弹出输入框,Name输入:Selenium2Library 点击OK 完。

如果导入的库显示为红色,表示导入的库不存在。如果是黑色则表示导入成功。

 

 

编写用例                                                      

   下面就可以开始写我们的用例了,可是怎么写呢?我们可以通过按F5 快捷键来查询脚本的关键字。如果你接触过QTP 或 selenium IDE 等自动化工具的话,应该会有一些思路。

   如上图,自动化脚本从打开浏览器开发,如上图,我想打开一个浏览器,想的是“open”为关键字进行搜索,结果找到了一个“Open Browser”的关键字,点击这个关键字,想显示它的用法和说明。

根据说明,我们来尝试创建这个打开浏览器的操作吧:

  “Open Browser”变蓝了,说明它是一个合法的关键字,后面有一个方框是红色的,表示这个参数不能缺省的。通过说明信息中,我发现它需要一个url 地址是必填的,当然还需要指定browser (默认不填为 friefox

  更多关键的使用,请参考相关API 文档。这里不过多介绍。按照上面的方法。创建百度搜索用例如下:

 

 

运行测试用例                                                

  勾选当前需要运行的测试用例,点击工具栏运行按钮,如果只运行单个用例的话,也可以切换到用例的Run标签页,点击“start”按钮。

 

运行信息:

  运行信息显示会生成三个文件:Output.xmlLog.htmlReport.html

  我们重点查看Log.htmlReport.html Log.html更关注脚本的执行过程的记录,Report.html更关注脚本的执行结果的展示。

赶快打开你的测试报告看看效果吧!

 

 

================================================================================

错误:

command: pybot.bat --argumentfile c:\users\keikei\appdata\local\temp\RIDEama2ym.d\argfile.txt --listener D:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py:52418 E:robot\测试项目

解决:

将“C:\Python27\Scripts ”添加到PATH环境变量中。命令提示符号查看,RF版本。提示pybot 不是内部命令,说明环境变量设置有问题。

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326995200&siteId=291194637