The Issue

We previously learned about Local Variables with Ruby for Watir Webdriver scripts. Now we can take a look at how we can implement them into our Cucumber feature files and step definitions.

The Code

When a Cucumber step definition needs a value passed to it, that value is assigned to a local variable defined between the pipes ‘|’ after the ‘do’. This variable is |text| for the below example

The step will check for text, and fail if none is found. Lets take a look at the feature file:

After running this file, we will see the following output:

The command line output displays the visible validations when the button is found, and the fail when it is not, as per our previously defined step.

The Takeaway

Local variables are a foundational concept of Cucumber step definitions. Understand how to implement these, and you can get started building your own step definitions.