Search code examples
python-3.xurlrobotframeworkweb-api-testing

Why square brackets in URL is not considered in API testing using robotframework?


I am trying to API test few APIs using Robot framework. when I try to test api with square brackets it is not getting considered and getting wrong response. Whereas the same API is able to give correct response in POSTMAN.

I have the below API: https://orbit.com/s2e/api/q1/client/?filter[customField.ID]=1003

When I hit in Postman I am getting valid response as:

 "data": {
    "total_count": "1",
    "customer": [
        {
            "id": "123" } ] }

The same API https://orbit.com/s2e/api/q1/client/?filter[customField.ID]=1003 hit in Robot framework gives:

"data": {
    "total_count": "0",
    "customer": [] }

Then I saw various encoding and found to use %5B and %5D instead of [ and ] but that API is working properly in postman but in robotframework, it is giving all data i.e filter not working.

https://orbit.com/s2e/api/q1/client/?filter%5BcustomField.ID%5D=1003 Can anyone guide me here?


Solution

  • Try to encode URL Path by create custom Library for Robotframework.

    For Python V2

    import urllib   
    def encodeUrlPath(s): 
       return urllib.quote_plus(s)
    

    For Python V3

    import urllib.parse
    def encodeUrlPath(s): 
      return urllib.parse.quote_plus(s)