Context
Using the RequestsLibrary to automate tests for sending XML Post Requests to a server and receiving a Response which should be validated.
The test currently Gets the 'payload' of an XML file and attempts to pass this as the 'data' argument for a Post Request.
The error
Using the RequestsLibrary on Robot Framework, the POST request continually leads to
<Response [500]>
and
Page can either not be found or displayed. <br />
Please try again or return to login.
within the repsonse body.
The problem
The response code we're looking for is of course 200 however 500 is continually received. Hence the response body contains
Page can either not be found or displayed. <br />
Please try again or return to login.
and not the required XML response, something like
><MsgType>ERROR</MsgType>
<MsgData><ERROR><CODE>0110</CODE><MSGTXT>Encryption
Failure</MSGTXT></ERROR></MsgData></ProcessMsgResult>
</ProcessMsgResponse></soap:Body></soap:Envelope>
which should be the sort of response for an invalid request.
The Code
Post request XML payload
Disable Warnings
Create Session Gateway https://URLHERE debug=3
${file_data}= Get Binary File ${CURDIR}${/}text.xml
&{headers}= Create Dictionary Content-Type text/xml
${resp}= Post Request Gateway /post data=${file_data} headers=${headers}
Log ${resp.text}
Log ${resp.status_code}
Should Be Equal As Strings ${resp.status_code} 200
This is the code I am running with the Post Request arguments for data
as ${file_data}
and headers
as ${headers}
. However, from the test run report, the ${file_data}
isn't being passed down correctly to the Post Request Keyword because it's using the <text/xml>
as the data argument and not ${file_data}
INFO : Post Request using : alias=Gateway, uri=/post, data=<text/xml>, headers={u'Content-Type': u'text/xml'}, files=None, allow_redirects=True
This is where the problem lies, and I'm not sure why for the data argument it's always data=<text/xml>
.
Question
Has anyone encountered this issue before of the argument not being passed down correctly? As I believe it should be data=<${file_data>
, the 500 response would no longer be received because the server would receive an understandable XML request.
_format_data_to_log_string_according_to_header
). It shouldn't be logging the full file anyway - what if it was 5MB big? – Todor Minakov