Robot Framework - Ride:Post Request无法获得响应机构

时间:2016-10-31 14:00:03

标签: robotframework

我写了这个测试,我在后台系统中发布合同。我用forloop创建了一个关键字,从系统文件夹中获取xmls。

为了使测试通过,我想检查de响应中的值。当我使用RF / Ride来执行此测试时,无法获得响应体,如果我在Postman / SoapUI中进行相同的测试,我可以看到响应体

当我要求回复时,我得到了预期的数据

骑行中的测试:

*** Test Cases *** XML
    [Template]    Template post contract BO
    apitest1.xml
*** Keywords *** Template post contract BO
    [Arguments]    @{bestandlijst}
    : FOR    ${bestand}    IN    @{bestandlijst}
    \    &{headers}=    Create dictionary    Content-type=application/xml
    \    ${bestandophalen}=    Get Binary File    ${bestand}
    \    Create Session    Backoffice    https://url        
    \    ${response}=    Post Request    Backoffice    /isCOBOL(API_V1_ARCONTRACT)    headers=&{headers}    data=${bestandophalen}
    \    log    ${response.headers} -> this works
    \    log    ${response.body} -> this doesn't work

邮递员的回应:

<?xml version="1.0" encoding="UTF-8"?>
<Retourbericht xmlns="http://url/schemas/things">
    <Statuscode>OK</Statuscode>
    <Statusmelding>Contract opgeslagen in de backoffice.</Statusmelding>
    <TransactionResponse>Onbekend.</TransactionResponse>
</Retourbericht>

骑行时出现错误:

FAIL : Resolving variable '${response.body}' failed: AttributeError: 'Response' object has no attribute 'body'
  1. 我的测试是否有错误,导致此错误?
  2. 有没有人遇到同样的问题,你的解决方案是什么?

1 个答案:

答案 0 :(得分:4)

如果您使用RequestsLibrary,它将构建在python requests库之上。此库返回响应对象,但该对象没有body属性。这就是你得到AttributeError的原因。

如果您需要结构化数据,可以使用${response.json()};如果希望将响应的原始文本作为字符串,则可以使用${response.text}

相关问题