RobotFramework 接口测试

请大家先看看RequestsLibrary和接口测试官方用例这2个官方链接

RequestsLibrary 库接口测试用例:

*** Settings ***        
Library Collections      
Library RequestsLibrary      
*** Test Cases ***        
Get Requests        
  Create Session github http://api.github.com  
  Create Session google http://www.google.com  
  ${resp}= Get Request google /
  Should Be Equal As Strings ${resp.status_code} 200  
  ${resp}= Get Request github /users/bulkan
  Should Be Equal As Strings ${resp.status_code} 200  
  Dictionary Should Contain Value ${resp.json()} Bulkan Savun Evcimen

    然后我们可以按照这样的思路去进行接口测试

    第1步:创建一个请求header信息(可以根据自己的情况添加所需的值,类似于jmeter的头文件,不一定是必须的,可以用作切换体验区或者稳定区)

    第2步:创建session,在get request或者post request时,可识别session。

    第3步:发起请求。返回对象${resp}

    第4步:判断请求响应是否为成功,${resp.status_code}  200

    第5步:判断需要判断的接口中的值,或者数据类型,或者数据格式等等  

                 判断返回的字典中是否包含abc:   Dictionary Should Contain Value ${resp.json()}  abc

                 判断返回的字典中code是否为0:  Should Be Equal As Strings ${resp.json()['code']}  0

扫描二维码关注公众号,回复: 3177535 查看本文章

                 判断返回的字典中result不能为空:Should not be empty  ${resp.json()['result']}

标准库

官方链接

RequestsLibrary http://bulkan.github.io/robotframework-requests/
Collections http://robotframework.org/robotframework/latest/libraries/Collections.html
Builtln http://robotframework.org/robotframework/latest/libraries/BuiltIn.html
接口测试官方用例 https://github.com/bulkan/robotframework-requests/blob/master/tests/testcase.txt

猜你喜欢

转载自blog.csdn.net/weixin_41407477/article/details/81382895
今日推荐