机器人框架 - 骑行:Post 请求无法获取响应正文
Robot Framework - Ride: Post Request unable to get response body
我写了这个测试,其中我 post 后台系统中的合同。我用 forloop 创建了一个关键字,它从系统文件夹中获取 xml。
为了让测试通过,我想检查响应中的值。当我使用 RF/Ride 执行此测试时,无法获得 responsebody,如果我在 Postman/SoapUI 中执行相同的测试,我可以看到 responsebody
当我请求 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'
- 我的测试是否有错误,导致了这个错误?
- 有没有人遇到同样的问题,你的解决方案是什么?
如果您正在使用 RequestsLibrary, it is built on top of the python requests 库。此库 returns 一个响应对象,但该对象没有 body
属性。这就是你得到 AttributeError 的原因。
如果您想要结构化数据,您可以使用 ${response.json()}
,如果您想要响应的原始文本作为字符串,则可以使用 ${response.text}
。
我写了这个测试,其中我 post 后台系统中的合同。我用 forloop 创建了一个关键字,它从系统文件夹中获取 xml。
为了让测试通过,我想检查响应中的值。当我使用 RF/Ride 执行此测试时,无法获得 responsebody,如果我在 Postman/SoapUI 中执行相同的测试,我可以看到 responsebody
当我请求 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'
- 我的测试是否有错误,导致了这个错误?
- 有没有人遇到同样的问题,你的解决方案是什么?
如果您正在使用 RequestsLibrary, it is built on top of the python requests 库。此库 returns 一个响应对象,但该对象没有 body
属性。这就是你得到 AttributeError 的原因。
如果您想要结构化数据,您可以使用 ${response.json()}
,如果您想要响应的原始文本作为字符串,则可以使用 ${response.text}
。