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