The software I am testing with Robot Framework offers a REST API as main entry point. So the question arose of what library to use to write my Robot tests.
First one I tried was the robotframework-restlibrary.
- Pro: it is test-oriented and works well with Robot
- Con: some features are missing (inspecting returned headers for example) and there is no community/activity around it (no commit since 2009)
I used it for a couple of weeks for my first tests but once I reached the limitations of the library, I quickly looked for another one.
I bumped into 2 others libraries tagged as “REST” and “Robot Framework”
but none of them seemed to be a good fit for me (not much documentation, not the right level of keywords, not very active…). Though, the second one was built on “requests library” which seemed to be worth looking at.
Requests Python Library is not Robot or Test oriented but the feature support is very wide, the use guide is very detailed and the community looks very active.
Here is a simple example of how to use it with Robot Framework:
(we use jstontest.com that sends back a json object when we do a get)
*** settings *** Library Collections Library requests *** test cases *** simpleRequest ${result} = get http://echo.jsontest.com/framework/robot-framework/api/rest Should Be Equal ${result.status_code} ${200} ${json} = Set Variable ${result.json()} ${framework} = Get From Dictionary ${json} framework Should Be Equal ${framework} robot-framework ${api} = Get From Dictionary ${json} api Should Be Equal ${api} rest |
The trick then is to create appropriate keywords for often-used command.
For example, to check the value of a property in a one-level json object, we could have this keyword:
json_property_should_equal [Arguments] ${json} ${property} ${value_expected} ${value_found} = Get From Dictionary ${json} ${property} ${error_message} = Catenate SEPARATOR= Expected value for property " ${property} " was " ${value_expected} " but found " ${value_found} " Should Be Equal As Strings ${value_found} ${value_expected} ${error_message} values=false |
I am still looking for a good json lib to create/read/update my json objects.
In the meantime I built a collection of keywords like the one mentioned here.
Hope this help some people facing the same kind of starting point (robot + rest + json).
Ping me if you want some more details.