POST'ing JSON with Robotframework-requests

4,988 views
Skip to first unread message

nvill...@despegar.com

unread,
Jun 29, 2015, 6:31:57 PM6/29/15
to robotframe...@googlegroups.com

Hello all,

I'm trying to create a test case using the Requests library.
The issue I ran into is that I'm communicating with an API that expects to receive data in JSON format. What I thought about doing is to have a Python dict in a module for easy editing and whatnot.
Now, in my code, I loaded this module via the Variables keyword, and used it in my test case as such:

${resp} Post Request api ${V1_ROOT}/auth/signup data=${VALID_USER} headers=${APPLICATIONJSON}

That ${VALID_USER} variable is picked up just fine, but what the keyword "Post Request" does, is to convert this dict into a urlencoded string. I need it to send it over as-is.

Sniffing traffic with Wireshark, shows me this:

URL encoded data

And I need this:

Raw dict

(request sent with Postman)


Is there something I'm missing here?


Thanks a lot!


Gu Ru

unread,
Jun 30, 2015, 12:58:04 AM6/30/15
to robotframe...@googlegroups.com
I had a similar issue. i added the stingify_json method as in robotframework-httplibrary to the robotframework-requests library. This patch of code helped

nvill...@despegar.com

unread,
Jul 1, 2015, 9:38:47 AM7/1/15
to robotframe...@googlegroups.com
Yeah, I thought about extending it too... If there's no other way, I'll have to go with it.
Thanks a lot!

Nesat Ufuk

unread,
Jul 3, 2015, 4:50:42 AM7/3/15
to robotframe...@googlegroups.com
I came over this using json library and using new &{DICTIONARY} variable type.

After creating my &{DICTIONARY}, I have converted it to json with like below.

*** Settings ***
Library           json

*** Test Cases ***
${json_data}=   json.dumps   ${DICTIONARY}
${headers}=   Create Dictionary   Content-type=application/json
${resp}=  Post Request   CS   api/v1/sale/   data=${json_data}   headers=${headers}

Hope that will help.

P.s
json.dumps  -> Dictionary to Json
json.loads    -> Json to Dictionary
Reply all
Reply to author
Forward
0 new messages