Karate - want to get url along with query params in a variable

Viewed 983

Karate version - 1.0.0

I want to get the queryparams and url and want to concat it and save it to a variable.. I'm using following syntax which doesn't work. when I use param in variable it says param not defined. Does anyone have any work around for this? When I use the following -

Given path '/test/1'
    And param product = "abc"
    And param country = "usa"
    * print param

org.graalvm.polyglot.PolyglotException: ReferenceError: "param" is not defined

How do I concat url and param and get in a variable.

Many thanks!

1 Answers

Following is the example with the corresponding request url & query params for which you can execute this scenario to get the response and GET Request as,

Scenario: Sample File
* def ScenarioEngine = Java.type('com.intuit.karate.core.ScenarioEngine');
Given url 'https://reqres.in'
And path '/api/users'
And param page = 2
And param pages = 1
When method get
And print ScenarioEngine.get().getRequest().getUrl()

For which the response would be printed along with the GET url and query param as, [print] https://reqres.in/api/users?pages=1&page=2

Related