Karate Http request add param conditionally

Viewed 104

Is there any way to add param conditionally?

I have the following request :

Given url "http://myURL"
And param time = time
When method DELETE
Then status  200

For example if time is 'undefined' or 'null' then completely ignore param time?

I know I can concatenate strings conditionally but I am looking for a better way.

1 Answers

Actually path is designed so that a null value will be ignored. Also see params. I think that solves your problem.

EDIT: you can use karate.get('variableName') if you are dealing with variables that are undefined (although this is not recommended as it reduces maintainability of your tests).

* def time = karate.get('externalTime')
Related