目录

一文2500字Robot-Framework自动化测试框架超强教程

一文2500字Robot Framework自动化测试框架超强教程

https://i-blog.csdnimg.cn/blog_migrate/0991f4ea49dfe9d6e3147cc0580570fb.png

1、Robot Framework简介

https://i-blog.csdnimg.cn/blog_migrate/d795386c34ec48c5776fa99da55b765a.png

Robot Framework是一个基于Python的可扩展关键字驱动的自动化框架,用于验收测试,验收测试驱动开发(ATDD),行为驱动开发(BDD)和机器人流程自动化(RPA)。 它可以用于分布式异构环境,其中自动化需要使用不同的技术和接口。由Robot Framework基金会支持。许多行业领先的公司在其软件开发中使用该工具。

Robot Framework是开放和可扩展的。可以与几乎任何其他工具集成,以创建强大而灵活的自动化解决方案而著称。Robot Framework可以免费使用,无需许可费用。

2、 Robot Framework 框架特点

1、RF支持易于使用的表格语法,以便以统一的方式创建测试用例。

2、RF提供从现有关键字创建可重用的高级关键字的功能。

3、提供易于阅读的HTML 格式结果报告和日志。

4、独立于平台和应用程序。

5、提供用于创建可使用 Python 本机实现的自定义测试库。

6、提供命令行界面和基于 XML 的输出文件,以便集成到现有的生成基础结构(持续集成系统)中。

7、支持测试 Web 应用程序、rest API、移动应用程序、正在运行的进程、通过 Telnet 或 SSH 连接到远程系统等。

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

9、具有对变量的内置支持,特别适用于在不同环境中进行测试。

10、提供标记以分类和选择要执行的测试用例。

11、支持集成:测试套件只是可与生产代码一起进行版本控制的文件和目录。

12、提供测试用例和测试套件级别的设置和拆卸。

13、模块化架构支持创建测试,甚至适用于具有多个不同接口的应用程序。

3、 Robot Framework 框架的体系结构

Robot Framework是一个通用的,独立于应用程序和技术的框架。它具有高度模块化的体系结构,如下图所示。

https://i-blog.csdnimg.cn/blog_migrate/093d2aa0b813e43c7fd92358c19f31c5.png

测试数据采用简单、易于编辑的表格格式。当Robot Framework启动时,它会处理数据,执行测试用例并生成日志和报告。核心框架对被测目标一无所知,与它的交互由库处理。库可以直接使用应用程序接口,也可以使用较低级别的测试工具作为驱动程序。

4、 Robot Framework 应用示例

以下截图显示了测试用例和数据文件:

https://i-blog.csdnimg.cn/blog_migrate/a5e3ef9f9ce8dab6adb28921f7658bfc.png

结果和日志文件:

https://i-blog.csdnimg.cn/blog_migrate/bc92da0468f96f8cdefdf8e3d26ea65f.png

5 Robot Framework 安装

Robot Framework 是用 Python 实现的,因此需要安装 Python。在 Windows 计算机上,确保在安装过程中将 Python 添加到 PATH。

使用 pip 安装Robot Framework很简单:

https://i-blog.csdnimg.cn/blog_migrate/20fe14f8c393a424251e9b0fb6472bc1.png

安装命令运行的过程:

https://i-blog.csdnimg.cn/blog_migrate/e839350a5a34273a7eb94ad81155d0eb.png

安装完成后,用如下命令进行版本检查:

https://i-blog.csdnimg.cn/blog_migrate/d254f90c2d7fc9b26442ce8410f4ac68.png

6、 Robot Framework 简单示例

案例中包含2个文件:

Test_suite.robot文件

Keywords.resource文件

https://i-blog.csdnimg.cn/blog_migrate/1e712884c887c2d075607aa5d6d90bf4.png

1)创建一个robot文件(代码如下所示):

*** Settings ***Documentation     A test suite for valid login.......               Keywords are imported from the resource fileResource          keywords.resourceDefault Tags      positive
*** Test Cases ***Login User with Password    Connect to Server    Login User            ironman    1234567890    Verify Valid Login    Tony Stark    [Teardown]    Close Server Connection
Denied Login with Wrong Password    [Tags]    negative    Connect to Server    Run Keyword And Expect Error    *Invalid Password    Login User    ironman    123    Verify Unauthorised Access    [Teardown]    Close Server Connection
2)创建一个关键字文件:
*** 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 Server    Connect    fe80::aede:48ff:fe00:1122
Close Server Connection    Disconnect
Login User    [Arguments]    ${login}    ${password}    Set Login Name    ${login}    Set Password    ${password}    Execute Login
Verify Valid Login    [Arguments]    ${exp_full_name}    ${version}=    Get Server Version    Should Not Be Empty    ${version}    ${name}=    Get User Name    Should Be Equal    ${name}    ${exp_full_name}
Verify Unauthorised Access    Run Keyword And Expect Error    PermissionError*    Get Server Version
Login Admin    [Documentation]    'Login Admin' is a Keyword.    ...                It calls 'Login User' from 'CustomLibrary.py'    Login User    admin    @RBTFRMWRK@    Verify Valid Login    Administrator

end

最后感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走

https://i-blog.csdnimg.cn/blog_migrate/d16ab812b854300d91039e50703a439f.png

这些资料,对于做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!凡事要趁早,特别是技术行业,一定要提升技术功底。希望对大家有所帮助…….

https://i-blog.csdnimg.cn/blog_migrate/b8a101b6d7719ad49d36b48e81be483f.png