自动回复机器人api_使用机器人框架自动执行剩余api测试

自动回复机器人api

Robot Framework is language-agnostic open-source test automation framework for test automation and robotic process automation (RPA).It is operating system and application independent. Several standard libraries are bundled with the framework, and there are separately developed external libraries galore that can be installed based on your needs. Libraries provide the actual automation and testing capabilities to framework by providing keywords. Test cases are written using a keyword-testing methodology written in a tabular format. You get more information about it here

Robot Framework是与语言无关的开源测试自动化框架,用于测试自动化和机器人过程自动化(RPA),它独立于操作系统和应用程序。 框架捆绑了几个标准库,并且可以根据您的需要安装单独开发的外部库galore。 库通过提供关键字来为框架提供实际的自动化和测试功能。 测试用例使用以表格形式编写的关键字测试方法编写。 您可以在此处获得有关它的更多信息

为什么选择ROBOT框架? (Why ROBOT Framework ?)

Might be thinking there are already quite a number of Rest API testing frameworks like Postman, SoapUI, JMeter, Rest-Assured and several others.How is wrting test cases using Robot Framework different from others. Robot framework is language-agnostic, you need not learn any language or scripting for write test cases. ROBOT framework is not only for REST APIs testing, it can be used for testing GUI (using selenium library ), verify database (using database library) and there are many more libraries which can be leveraged.

可能会认为已经有很多Rest API测试框架,例如Postman,SoapUI,JMeter,Rest-Assured等。使用Robot Framework编写测试用例与其他有何不同? 机器人框架与语言无关,您无需学习任何语言或脚本即可编写测试用例。 ROBOT框架不仅用于REST API测试,还可以用于测试GUI(使用selenium库),验证数据库(使用数据库库),并且还有许多可以利用的库。

For example if you have test case with steps, perform REST API POST operation, check in DB to see object is created and fianlly verify POST response is valid. All the above steps can be verified in one test case written with ROBOT framework

例如,如果您有带有步骤的测试用例,请执行REST API POST操作,签入数据库以查看是否创建了对象,并最终验证POST响应是否有效。 以上所有步骤都可以在用ROBOT框架编写的一个测试用例中进行验证

使用RestInstance库 (Using RestInstance Library)

Here we will see how to use RESTinstace library that is part of the Robot framework to test RESTful APIs. The Keywords provided in the library are simple to use, supports all the methods (GET, PUT, POST, PATCH, DELETE) , supports sending custom the headers, keywords for validating the reasponse header and also validates JSON using JSON Schema.

在这里,我们将看到如何使用RESTinstace库(它是Robot框架的一部分)来测试RESTful API。 库中提供的关键字易于使用,支持所有方法(GET,PUT,POST,PATCH,DELETE),支持发送自定义标头,用于验证重新组合标头的关键字,还使用JSON Schema验证JSON。

Here is the sample test case

这是示例测试用例

*** Settings ***
Library String
Library REST http://echo.jsontest.com ssl_verify=falseSet expectations
Expect response { "status": { "enum": [200, 201, 204, 400] } }
Expect response { "seconds": { "maximum": 2} }*** Test Cases ***Get Employee
GET employee/1001
Output response body
String response body employee 1001

Above test case sends GET request to <url>/employee/1001 , and then verifies the following output API out in JSON format

上面的测试用例将GET请求发送到<url> / employee / 1001,然后以JSON格式验证以下输出API

{"employee": "1001"}

You can get more sample test cases from author of this library from here

您可以从此处从该库的作者那里获得更多示例测试用例。

运行测试用例 (Running the Test cases)

I have created Docker Image for Robot Framework and then installed RESTinstace library, so we can run tests isolated from the application. This kind of setup will be helpful for running smoke and regression tests after deploying the application and without distrubing the application. You can find scripts to build Docker image here.

我已经为Robot Framework创建了Docker Image,然后安装了RESTinstace库,因此我们可以运行与应用程序隔离的测试。 这种设置将有助于在部署应用程序之后运行烟雾和回归测试,而不会破坏应用程序。 您可以在此处找到用于构建Docker映像的脚本。

To build image run the script build_image.sh. Once the Docker image is create and available, you can use run_tests.sh to run test cases placed in tests folder

要构建映像,请运行脚本build_image.sh。 创建Docker映像并可用后,您可以使用 run_tests.sh 运行放置在测试文件夹中的测试用例

测试REST API的测试用例 (Test case to test REST API)

In test case i am using http://echo.jsontest.com to test REST API . Run the test case placed in tests folder using run_tests.sh , it launches a docker, copies the test cases and executes them.

在测试用例中,我使用http://echo.jsontest.com来测试REST API。 使用以下命令运行放置在tests文件夹中的测试用例 run_tests.sh 它启动 码头工人,复制测试用例并执行它们。

The Robot Framework output files are put in the same directory under results/. In the console you can see it has created log.html (detailed report) and report.html (execution summary)

Robot Framework输出文件放在results /下的同一目录中。 在控制台中,您可以看到它已经创建了log.html(详细报告)和report.html(执行摘要)

测试执行结果 (Test Execution Results)

Robot Framework genrates nice test report for all the test-case executed with detailed steps and execution status.

Robot Framework会为执行的所有测试用例生成详细的测试报告,并提供详细的步骤和执行状态。

Image for post

结论 (Conclusion)

Robot Framework can be used to write smoke and regression test cases and test the application in isolation and RestInstance is a powerful library in terms of JSON schema checking and validations. You can get more information about RESTInstance here

Robot Framework可以用来编写冒烟和回归测试用例,并隔离测试应用程序,而RestInstance是一个强大的库,可以进行JSON模式检查和验证。 您可以在此处获取有关RESTInstance的更多信息。

翻译自: https://medium.com/@ravthiru/automate-rest-api-testing-with-robot-framework-ad1959057517

自动回复机器人api

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值