请用RF写一个接口测试脚本呢
时间: 2024-06-05 13:06:34 浏览: 22
以下是一个使用Python的RF框架编写的简单接口测试脚本示例:
*** Settings ***
Library RequestsLibrary
*** Test Cases ***
Test GET Request
Create Session example https://jsonplaceholder.typicode.com
${response} Get Request example /posts
Should Be Equal As Strings ${response.status_code} 200
${json_data} Set Variable ${response.json()}
Should Be Equal As Strings ${json_data[0]['userId']} 1
Test POST Request
Create Session example https://jsonplaceholder.typicode.com
${headers} Create Dictionary Content-Type=application/json
${payload} Create Dictionary title=foo body=bar userId=1
${response} Post Request example /posts json=${payload} headers=${headers}
Should Be Equal As Strings ${response.status_code} 201
${json_data} Set Variable ${response.json()}
Should Be Equal As Strings ${json_data['title']} foo
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)