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

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

bdd - Karate: Query Param values are getting encoded

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...