apikarate

Karate DSL query parameter does not accept empty spaces and converts them to encoded charactesr


Parameter value does not accept special characters and throws syntax exception. Same URL works perfectly fine in postman

enter image description here

However in Karate there is concept of encoding and decoding which is tough to comprehend. Can you please provide example using the following scenario

Scenario: Searching owner name with family organisation name of characters greater than 141
Given path '/api/products/v1/ownerName/search'
And param familyOrgName = "MCLAREN VALE & DISTRICT SUB-BRANCH OF THE RETURNED SAILORS', SOLDIERS' AND AIRMEN'S IMPERIAL LEAGUE OF AUSTRALIA, SOUTH AUSTRALIAN BRANCH INC."
When method Get
Then status 200

enter image description here

karate version: 1.3.1

I tried to decode and encode the URL and refactored the code

  Scenario: Searching owner name with family organisation name of characters greater than 141
    * def encoded = 'MCLAREN+VALE+%26+DISTRICT+SUB-BRANCH+OF+THE+RETURNED+SAILORS%27%2C+SOLDIERS%27+AND+AIRMEN%27S+IMPERIAL+LEAGUE+OF+AUSTRALIA%2C+SOUTH+AUSTRALIAN+BRANCH+INC.'
    * def decoded = karate.urlDecode(encoded)
    Given url sailisUrlBase + '/api/products/v1/ownerName/search?familyOrgName=' + decoded
    When method Get
    Then status 200

ReportFailed


Solution

  • Pretty sure you have not set the url correctly. You can try this test and see it work. You can even see the server process the param correctly and echo it in the response:

    * url 'https://httpbin.org/anything'
    * path '/api/products/v1/ownerName/search'
    * param familyOrgName = "MCLAREN VALE & DISTRICT SUB-BRANCH OF THE RETURNED SAILORS', SOLDIERS' AND AIRMEN'S IMPERIAL LEAGUE OF AUSTRALIA, SOUTH AUSTRALIAN BRANCH INC."
    * method get
    * status 200
    

    And don't worry about encoding, Karate will do it automatically: https://stackoverflow.com/a/59977660/143475