【问题标题】:How can I send a GET request with json payload in the Robot Framework?如何在机器人框架中发送带有 json 有效负载的 GET 请求?
【发布时间】:2020-12-04 11:22:08
【问题描述】:

我查看了 RESTinstance 和 RequestsLibrary,但找不到将 GET 作为请求的一部分使用 JSON 发送到服务器的方法。我很感激任何建议。

【问题讨论】:

  • 欢迎。请添加我们的代码和所有相关的错误消息以及您尝试摆脱它们的方法。

标签: json get robotframework


【解决方案1】:

使用RequestLibrary 中的Get Request 关键字可以如下完成。 JSON 通常是 Robot Framework 中的 dictionary。在下面的示例中,&{JSON} 变量等同于以下 JSON:

{
  "name": "peter",
  "other_attribute": "value"
}

使用其他关键字,您也可以创建嵌套结构。


例子:

*** Settings ***
Library           RequestsLibrary

*** Variables ***
&{JSON}    name=peter    other_attribute=value

*** Test Cases ***
Test
    Create session    alias=my_session    url=http://127.0.0.1:5000
    ${response}=    Get Request    alias=my_session    uri=api/your_api_endpoint    json=${JSON}
    Log    ${response}

【讨论】:

    猜你喜欢
    • 2016-12-15
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-12
    相关资源
    最近更新 更多