Cucumber - Adding flexibility to scenario steps

How to make steps more flexible and consice

Providing alternatives

    Say you have a step where the same glue code can be reused for different scenarios. Rather than having multiple similar methods where the only thing that changes is a single word in the step name, use alternatives, like this

 @When("^I reply to the discussion (?:post|comment)$")  
   public void i_disregard_the_inappropriate_post() throws Throwable {  
     // code
   }  

Here you can write your step with like this:
I reply to the discussion post

or this:
I reply to the discussion comment

and both will trigger the same method.

Comments