I have a cuke scenario,
Scenario: Hello World
Then do action one
Then do action two
Then do action three
Then do action four
Then do action five
But depending on the environment variable, I want to skip action three
and action four
. I know I can go in the step and do a if-else check, but it's not very elegant. Is there any better solution? Thanks :)
You can't do this in Gherkin, nor should you want to! Gherkin is not for programming, nor is it for stating 'how' things are done, instead its for stating 'what' things are and 'why' they are done.
In general when you find yourself wanting to program in Gherkin (loops, conditionals etc.) what you want to do is
In your case you could do this by
and
and use state set in the Given to allow conditional behaviour in the When
e.g.
Its much simpler and more productive to use Cucumber as its intended, rather than trying to make it do exactly what you want. Cucumber is not a general purpose testing tool, you're best either changing how you going to use it, or using a different tool. Good luck ...
You can create two scenarios and use tags to filter them:
Then you can execute just the simple scenarios running:
You can have code within the steps that recognizes the environment variables.
That's just an example. The code could do whatever you wanted.