【问题标题】:rest webservice testing through robotframework tool通过机器人框架工具进行REST Web服务测试
【发布时间】:2018-05-23 02:52:24
【问题描述】:
【问题讨论】:
标签:
web-services
rest
robotframework
【解决方案1】:
要测试 RESTful 服务,您可以使用 Requests 库。这个库的主页是https://github.com/bulkan/robotframework-requests/
要测试 SOAP 服务,您可以使用 Suds 库。这个库的主页是https://github.com/ombre42/robotframework-sudslibrary
robotframework 主页上提供了这两个链接以及许多其他链接。这是一个快速链接:
http://robotframework.org/#test-libraries
这是一个连接到 RESTful 服务并验证它是否返回状态码 200 以及 JSON 数据具有一些特定键的示例(请注意,此测试在我编写它时通过了,但如果从我写到你读到这里,API 发生了变化,它可能会失败)
*** Settings ***
| Library | RequestsLibrary
| Library | Collections
*** Variables ***
| ${SERVICE_ROOT} | http://api.openweathermap.org
| ${SERVICE_NAME} | openweathermap
*** Test Cases ***
| Example RESTful API test
| | [Documentation] | Example of how to test a RESTful service
| |
| | Create session | ${SERVICE_NAME} | ${SERVICE_ROOT}
| | ${response}= | Get | ${SERVICE_NAME} | /data/2.5/weather?q=chicago,il
| |
| | Should be equal as numbers | ${response.status_code} | 200
| | ... | Expected a status code of 200 but got ${response.status_code} | values=False
| |
| | ${json}= | To JSON | ${response.content}
| | :FOR | ${key} | IN
| | ... | coord | sys | weather | base | main | wind | clouds | dt | id | name | cod
| | | Run keyword and continue on failure
| | | ... | Dictionary should contain key | ${json} | ${key}
| | | ... | expected json result should contain key '${key}' but did not