1

I have a boolean variable in my feature file and I wanted to add Given/And/When/Then statements based on a condition.

For example -

* def boolVar = true
Given url 'https://test.com/test/api1'
And params {'key1':'value1'}
When method POST
Then match responseStatus == 200

* def boolVar = false
Given url 'https://test.com/test/api1'
When method POST
Then match responseStatus == 200

So when boolVar=true I want statement 'And params {'key1':'value1'}' to be set but not when boolVar=false.

Does Karate support this?

I tried like this but it isn't working -

* def boolVar = true
Given url 'https://test.com/test/api1'
And params {'key1':'value1'}
And eval if (boolVar)
"""
* params {'key1':'value1'}
"""
When method POST
Then match responseStatus == 200
  • karate does not support conditional logic for code API steps. this is intentional. may I offer some advice. I think you have fallen into the trap of "overly clever" tests. I strongly discourage this. for why, please read this: https://stackoverflow.com/a/54126724/143475 – Peter Thomas Jul 19 '23 at 14:34

0 Answers0