Using Optional Capture and Noncapture Groups

Until now, we have covered how to write Step Definitions for various keywords in Feature files. Now let's talk about how we can efficiently use Step Definitions for multiple Steps.

Think about a situation where we are testing a positive situation in one Step and a negative situation in some other Step—the only difference in both Steps is just the word "No", while the remaining sentence is same. Based on the knowledge that we have acquired so far, we will write two Step Definitions for these two Steps. But is there a better way of doing this? Let's see how we can do this better in this recipe.

How to do it…

  1. For this recipe, consider the following Scenarios and focus on the highlighted text:
    Scenario: Optional ...

Get Cucumber Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.