1
votes

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>&lt;ERROR&gt;&lt;CODE&gt;0110&lt;/CODE&gt;&lt;MSGTXT&gt;Encryption 
Failure&lt;/MSGTXT&gt;&lt;/ERROR&gt;</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.

2
The issue most probably comes from the server - its response is a semi-generic 500 error; does it require authentication - this might be the case with this wording? This is very app-specific, and as you probably can't share the actual url nor the API protocol in this public forum, you have to look for the issue yourself. Also, don't presume the file's content is not in the request - this is just how it gets to the log, judging by the lib's source (the class method _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
File only 2KB. Okay, thanks for the suggestion regarding authentication. Will look into this. And, I see, with the class method as '_format_data_to_log_string_according_to_header' the log shows the data as the header name.RangHu
Did it work with auth?Todor Minakov
unfortunately auth isn't the problem. i believe it's in the XML payload. server not liking the actual XML request.RangHu

2 Answers

-1
votes

I was also getting the same response code 500 while using the same keywords.

The correct solution which worked for me was -

Create Session iamconnected http://10.204.17.117:8085/ ${Request_Header} Create Dictionary Content-Type=text/xml; charset=utf-8 ${Request_Body} Get File IF1021VE.xml ${resp} Post Request iamconnected Runner/services ${Request_Body} headers=${Request_Header}

So in this code , the fully qualified URL was - http://10.204.17.117:8085/Runner/services

Runner/services is the params which I have passed.

I am using pre-built Operating System Library for Get File for getting the contents from XML file

iamconnected is my alias.

RequestsHeader is my header

Note : While I was using Dictionary as it is mentioned in Requests Library page , I was getting the same server response code 500

-1
votes

Incorrect

Create Session      aliasName   url=http://address/sub1/sub2/sub3
${resp}=    Post Request  alias=aliasName   uri=/  data=${file_data}   headers=${headers}

Correct

Create Session      aliasName   url=http://address/
${resp}=    Post Request  alias=aliasName   uri=sub1/sub2/sub3  data=${file_data}   headers=${headers}