【发布时间】:2016-10-31 22:28:02
【问题描述】:
我编写了这个测试,我在后台系统中发布了一份合同。我用一个forloop创建了一个关键字,它从系统文件夹中提取xml。
为了使测试通过,我想检查响应中的值。当我使用 RF/Ride 执行此测试时,无法获取响应体,如果我在 Postman/SoapUI 中进行相同的测试,我可以看到响应体
当我询问 response.headers 时,我得到了预期的数据
Ride 中的测试:
*** 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
Postman 中的响应:
<?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'
- 我的测试是否有错误导致此错误?
- 有没有人遇到过同样的问题,您的解决方案是什么?
【问题讨论】:
-
你用的是什么库?是否记录了返回具有
body属性的对象?标准 python 请求库不返回具有body属性的对象。 -
我们使用 requests 库。嗯,这是一个很好的问题,我的同事也使用它,并且对他有效。好吧,他的 api 给出了 json 响应和我的 xml。我检查了图书馆,但找不到任何关于返回对象的信息
标签: robotframework