【问题标题】:Test CRUD Web services with Robot Framework使用 Robot Framework 测试 CRUD Web 服务
【发布时间】:2015-03-08 18:25:53
【问题描述】:

使用 Robot Framework 来测试使用 JSON 媒体类型的 CRUD(或面向资源的)Web 服务 的最简单方法是什么?

阅读交互示例:

GET /user/666 HTTP/1.1
Host: example.com


HTTP/1.1 404 Not Found

创建交互示例:

POST /user HTTP/1.1
Host: example.com
Content-Type: application/json

{
    "firstname":"Webber",
    "lastname":"Jim"
}


HTTP/1.1 201 OK
Content-Type: application/json

{
    "id": 9780596805821,
    "firstname":"Webber",
    "lastname":"Jim"
}

【问题讨论】:

    标签: json rest http robotframework


    【解决方案1】:

    可以像这样使用standard librariesrobotframework-requests

    *** Settings ***
    Library        Collections
    Library        OperatingSystem
    Library        RequestsLibrary
    
    *** Test Cases ****
    Create User
             Create Session      example    http://example.com
      ${file_data}= 
        ...  Get Binary File     ${RESOURCES}${/}normal_user.json
      ${headers}=
        ...  Create Dictionary   Content-Type    application/json
      ${resp}=
        ...  Post Request        example    /user    data=${file_data}    headers=${headers}
             Should Be Equal As Strings
               ...               ${resp.status_code}  201
             Dictionary Should Contain Key
               ...               ${resp.json()}       id
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-12
      • 2014-12-09
      • 2021-04-19
      • 2015-01-31
      • 2018-01-11
      • 2016-01-13
      • 2017-08-08
      • 2020-07-12
      相关资源
      最近更新 更多