【问题标题】:RobotFramework Post Request with attributes on bodyRobotFramework 发布请求,主体上有属性
【发布时间】:2021-08-06 13:55:12
【问题描述】:

您好,我正在尝试使用正文测试 api:

{
  "customerAttributes": [
    {
      "customerId": 0,
      "id": 0,
      "name": "string",
      "value": "string"
    }
  ],
  "emailAddress": "string",
  "firstName": "string",
  "id": 0,
  "lastName": "string",
  "registered": true
}

由于它有多个对象,我不知道如何使它工作。这就是我目前所拥有的:

*** Settings ***

Library  RequestsLibrary

*** Variables ***

${Base_URL}=     http://localhost:8082 /api/v1



    *** Test Cases ***
    TC_004_POST_Customer
    
        Create session  customer   ${Base_URL}
        ${body}=    create dictionary   customerId=100    id=100    name=test    value=0  emailAdress=blabla@gmailcom    firstName=algo    id=101    lastName=testt    registered=true
        ${header}=  create dictionary   Content-Type=application/json
        ${response}=    Post On Session    customer     /customer       data=${body}        headers=${header}
        log to console  ${response.status_code}
        log to console  ${response.content}

有人可以帮我吗?谢谢!

【问题讨论】:

    标签: java post robotframework broadleaf-commerce document-body


    【解决方案1】:

    你应该可以做这样的事情:

    ${inner}=  Create Dictionary  customerId=100  id=100  name=test  value=0
    ${array}=  Create List  ${inner}
    ${body}=   Create Dictionary  customerAttributes=${array}  emailAdress=blabla@gmailcom  firstName=algo  id=101  lastName=testt  registered=True
    

    【讨论】:

    • Dint 工作 :( 我应该改变其他东西作为回应还是?
    • 如果您收到 json 响应,也可以将 Accept=application/json 添加到您的标头中。不知道是不是你发代码的方式,但是你的意图不正确,Base_url中还有一个空格。
    【解决方案2】:

    您必须在 POST on Session 关键字中使用 json 参数,如下所示:

        TC_004_POST_Customer
        
            Create session  customer   ${Base_URL}
            ${body}=    create dictionary   customerId=100    id=100    name=test    value=0  emailAdress=blabla@gmailcom    firstName=algo    id=101    lastName=testt    registered=true
            ${header}=  create dictionary   Content-Type=application/json
            ${response}=    Post On Session    customer     /customer       json=${body}        headers=${header}
            log to console  ${response.status_code}
            log to console  ${response.content}
    

    这是文档POST On Session Keyword

    【讨论】:

    • 太棒了!谢谢,现在它确实起作用了:D 只需像您说的那样将数据更改为 json。谢谢
    猜你喜欢
    • 1970-01-01
    • 2014-12-10
    • 1970-01-01
    • 1970-01-01
    • 2016-09-30
    • 1970-01-01
    • 1970-01-01
    • 2019-11-07
    • 1970-01-01
    相关资源
    最近更新 更多