Sunday, January 7, 2018

How to write a Feature and Scenario using Gherkin language?

Gherkin is the language Cucumber uses to write the tests. Gherkin uses simple English words Given, When, Then, And and etc. as keywords to write the tests.

Step 1: Creating a Feature file

Create a package like 'features', right click on it --> New --> Select File. Enter the file name with '.feature' extension. And then click 'OK' button.

You should see the file being created, and Cucumber green color icon before its name.

Step 2: Writing a Feature

Start with 'Feature' keyword and write the feature we are going to validate as below. We can write comments below it

Step 3: Writing a Scenario

When you press enter after writing Feature, the cursor starts after two spaces indentation. For pretty formatting Cucumber follows indentation.

Start a line with keyword 'Scenario' and write the scenario to be validated. You can write any number of scenarios in a feature.

Step 4: Writing the Steps

Use the Gherkin keywords like Given, When, And, Then to write the steps as below. Here we are taking two simple scenarios of Gmail login page
And you should see steps being highlighted in some kind of yellow color. The reason is this steps are haven't got their step definitions.

In the next post we will write the step definitions for the steps written. We will go step by step and I do not want to make it clumsy.

Thanks for reading!! #seleniumbabu #HappyLearning


  1. Wonderful blog on Selenium automation testing and it plays a major role in each and every organization. Thanks for providing such a wonderful article.
    Selenium Training in Chennai
    Selenium Training

  2. Thanks for providing the information . The articles in your blog helped me a lot for improving the knowledge on the subject. Also check my small collection on this at selenium Online Training blog


Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...