Background: New to Robot Framework but attempting at using the RequestsLibrary together with OperatingSystem and XML to automate some REST testing on RIDE.
Requirement: Sending file with XML body and validate after receiving the XML response from the server.
Problems: Current setup leading to 500 internal server error.
Is it possible to send the content of the XML file to the server instead of the XML file itself?
Is it possible to return the content of the response from the server instead of the response code?
Have spent a while searching already for pointers but not found anything overly helpful with most requests and response dealing with JSON instead of XML.
Ideal flow:
1)extract XML file content from file in directory
2)send as POST request to server URL
3)wait for response
4)return this XML response and validate it is correct
CODE:
*** Settings ***
Library Collections
Library RequestsLibrary
Library XML
Library Selenium2Library
Library OperatingSystem
*** Test Cases ***
Example 1
Create Session Gateway https://GatewayURL.asmx
${file_data}= Get Binary File ${CURDIR}${/}data.xml
${files}= Create Dictionary ${file_data}
${response}= Post Request Gateway /post files=${files}
I've added to code using the helpful suggestions.
Post request data in dictionary SAMPLE
Create Session Gateway URL HERE debug=3
${file_data}= Get Binary File ${CURDIR}${/}data.xml
&{data}= Create Dictionary name=${file_data.strip()}
&{headers}= Create Dictionary Content-Type=text/xml
${resp}= Post Request Gateway /post data=${data} headers=${headers}
Should Be Equal As Strings ${resp.status_code} 200
N.B URL HERE used as unfortunately not able to share this URL.
Failure is as follows. Not sure why data is text/xml when this has been used for the header. This is causing a server 500 error.
Post Request using : alias=Gateway, uri=/post, data=<text/xml>, headers={u'Content-Type': u'text/xml'}, files=None, allow_redirects=True
500 != 200
I want to send the content of the XML file not the XML file itself as the server 'wont know how to handle' the file but will be able to 'handle' the actual content of the XML file.
Have you encountered this problem before where RF is not accepting the data argument for the Post Request Keyword? It's always using the Header argument for Data for some reason...