Warm tip: This article is reproduced from stackoverflow.com, please click
api python-3.x robotframework url web-api-testing

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

发布于 2020-03-27 15:45:13

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?

Questioner
anj
Viewed
90
Sidara KEO 2020-01-31 18:23

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)