top of page

First Selenium Test And Mapping In Cucumber

How To Create And Run Selenium Test In Cucumber ?

*Before moving ahead let's convert the project in Cucumber project :

Right-click on your project.

Move to an option 'Configure' and click on 'Covert to Cucumber Project'.

For creating a selenium test in cucumber, first add selenium dependency in pom.xml of your project :




Create a java packge in src/main/java as 'stepdefinitions' .

Now create a step-definition class inside the above package as '' as :

package stepdefinitions;

import org.openqa.selenium.WebDriver;


public class Steps {
   @Given("^Navigate to$")
   public void navigateToUrl() throws Throwable {

       // Write code here that turns the phrase above into concrete actions
       WebDriver driver = new ChromeDriver();



Create a '.feature' extension file inside 'Features' folder of  the project as 'feature.feature' .

For an example,write below scenario in feature file :

Feature: Title of your feature
  I want to use this template for my feature file

Scenario: Navigate to a url
        Given Navigate to

*Here,'Scenario' and 'Given' are Gherkin keywords that we will discuss in further articles.

Run feature.feature file as 'Cucumber Feature'.

Following output would be displayed :

Scenario: Navigate to a url    # Features/feature.feature:4

   Given Navigate to # stepdefinitions.Steps.navigateToUrl()

1 Scenarios (1 passed)
1 Steps (1 passed)

Mapping Of Step-Definition Class With Feature File

To achieve mapping ,what we pass in annotaion as argument in step-definition class must be same as the statement of that annotaion in its feature file.

In above example,we can see :

In step-definition class -

 @Given("^Navigate to$")

And in feature file -

Given Navigate to

Refer next page JUnit Test Runner Class

bottom of page