robotframework接口测试实例
时间: 2023-08-27 15:06:29 浏览: 106
robotframework接口测试案例.pdf
以下是一个使用Robot Framework进行接口测试的示例:
*** Settings ***
Library RequestsLibrary
Library Collections
Library JSONPathLibrary
*** Test Cases ***
登录
${headers} Create Dictionary Content-Type=application/json User-Agent=Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
Create Session app http://127.0.0.1:8090
${data} Set Variable {"password":"12345678","username":"liuhao"}
${response} Post Request app /api/admin/login data=${data}
${json_response} To Json ${response.content}
log ${json_response}[data][access_token #获取token
log ${response}.status
Should Contain ${response}.status 200
log 登录成功。
这个示例中使用了RequestsLibrary、Collections和JSONPathLibrary这三个库来进行接口测试。首先,我们创建了一个字典${headers}来存储请求头信息。然后,通过Create Session关键字来创建与接口的会话。接下来,我们设置了请求参数${data},并使用Post Request关键字发送POST请求。通过To Json关键字将返回的数据转换为JSON格式,并使用log关键字打印出某个字段的值。最后,使用Should Contain关键字来断言返回的状态码是否为200,表示登录成功。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [【转载】Robot Framework--完整的接口测试用例](https://blog.csdn.net/xiaotongmu/article/details/113994641)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [RobotFramework 接口自动化实战案例](https://blog.csdn.net/qq_38484679/article/details/115401119)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文