Robotframework POST request with REST API.
Folks,
I have spent recently 2 days to get my things done. Scenario is like i need to simply login with json data (Parameters email & password) in post request. But challenge is how and with which library ? What should be correct format of passing parameters to post request ? .... and so on.
I have tried with 2 libraries and searched a lot to get my things done but not got any satisfactory response.
Finally i did it and share it here so that anyone can be benefited from this.
Feel free to share your views/comments/query.
*** Settings ***
Library Selenium2Library
Library Collections
Library OperatingSystem
Library json
Library HttpLibrary.HTTP
Library String
Library RequestsLibrary
Library ../Python27/Lib/site-packages/RequestsLibrary/RequestsKeywords.py
LoginPost
Create Http Context 12.34.56.789 http
Set Request Header Content-Type application/json
Set Request Header Authorization Bearer
${dict}= Create Dictionary email abcadmin@domain.com password admin
${value}= Stringify Json ${dict}
Set Request Body ${value}
HttpLibrary.HTTP.POST /auth/local?subdomain=newtest
Response Status Code Should Equal 200
${result_text}= Get Response Body
${result_json}= Parse Json ${result_text}
Stay tuned for more such interesting tech news & hacks.
I have spent recently 2 days to get my things done. Scenario is like i need to simply login with json data (Parameters email & password) in post request. But challenge is how and with which library ? What should be correct format of passing parameters to post request ? .... and so on.
I have tried with 2 libraries and searched a lot to get my things done but not got any satisfactory response.
Finally i did it and share it here so that anyone can be benefited from this.
Feel free to share your views/comments/query.
*** Settings ***
Library Selenium2Library
Library Collections
Library OperatingSystem
Library json
Library HttpLibrary.HTTP
Library String
Library RequestsLibrary
Library ../Python27/Lib/site-packages/RequestsLibrary/RequestsKeywords.py
LoginPost
Create Http Context 12.34.56.789 http
Set Request Header Content-Type application/json
Set Request Header Authorization Bearer
${dict}= Create Dictionary email abcadmin@domain.com password admin
${value}= Stringify Json ${dict}
Set Request Body ${value}
HttpLibrary.HTTP.POST /auth/local?subdomain=newtest
Response Status Code Should Equal 200
${result_text}= Get Response Body
${result_json}= Parse Json ${result_text}
Stay tuned for more such interesting tech news & hacks.
Thank you so much.
ReplyDeletethank you very much , this solved my problem. GBU
ReplyDeleteGlad to know that. Feel free to ask any queries/concerns if you have.
ReplyDelete