我无法在robotframework中返回POST API的值

时间:2019-01-08 08:54:34

标签: robotframework

我正在尝试自动化一些API测试,我正在使用robotframework。我正在尝试使用ExtendedRequestsLibrary获得发布API的响应。我得到的是500码而不是200。当我使用邮递员发送时,我得到200。我的Body参数解析可能出问题了。有人可以帮忙吗?

这是我的代码:

2.3. ResourceInventoryManagement
    AuthorizationTokenGenerator
    ExtendedRequestsLibrary.Create Session    TestName    ${ResourceInventoryManagementURL}
    &{headers2}=    Create Dictionary    Authorization=Bearer ${AuthToken}    Body={"provideAlternative": true}    Content-Type=application/json    transactionId=5
    ${result}=    ExtendedRequestsLibrary.Post Request    TestName    ${ResourceInventoryManagementSubURL}    headers=${headers2}
    Set Global Variable    ${result}
    Log    ${result}
    Log    ${result.json()}

1 个答案:

答案 0 :(得分:0)

Body={"provideAlternative": true}字典中的${headers2}键:值对是什么?
该库不会抱怨,并在请求的标头中发送它(使用{}字符编码)-但这看起来确实像一个有效负载。您当前未发送的有效负载,对于其余API中的发布请求而言,这有点不合常规。

如果该数据实际上是有效载荷,请将其作为关键字data参数的值传递:

&{headers2}=    Create Dictionary    Authorization=Bearer 
${AuthToken}    Content-Type=application/json    transactionId=5
${body}=      Create Dictionary    provideAlternative    ${True}
${result}=    ExtendedRequestsLibrary.Post Request    TestName    ${ResourceInventoryManagementSubURL}    headers=${headers2}    data=${body}