Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using karate 0.6.1 version and facing issue with get request with queryparam.

Scenario Outline: Verify the response Data with account details when there are filter values are provided with wildcard

 Given params { <paramName>: <paramValue> }
 When method get
 Then status 200
 Examples:
   | paramName | paramValue |                                                                                                                                                                                                                                                 
   | Name       |  'Volvo%' |
   | Name       |  'test data'|

in the request url with queryparam becomes like url?Name=Volvo%25 And url?Name=test+data

which is not correct, how should i resolve that.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

It is actually not wrong,

Url encoding is required to differentiate between special characters in your data vs special characters that are reserved to construct the URL.

Reserved Characters URL Encoding:

:   Separate protocol (http) from address encoded as %3B
/   Separate domain and directories encoded as %2F
#   Separate anchors encoded as %23
?   Separate query string encoded as %3F
&   Separate query elements encoded as %24
@   Separate username and password from domain encoded as %40
%   Indicates an encoded character encoded as %25
+   Indicates a space encoded as %2B
<space> Not recommended in URLs encoded as %20 or +

so if you are going to pass any special characters as data via URL you need to % encode them to avoid conflicts.

In karate, if you want to avoid your URL getting encoded, don't construct your URL using path, params, param definitions.

Instead, build your entire URL as a string and pass it to url. like,

* url 'http://httpbin.org/get?Name=Stark'

You might get an exception if you are trying to pass any special characters in this.

so consider encoding the URL if you are going to pass any special characters.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...