Cucumber – Integration with Selenium

In this tutorial, we will integrate Cucumber with Selenium WebDriver.

Let us consider a scenario to automate using Cucumber Selenium:

  • Navigate to Facebook website
  • Enter correct username and password
  • Click on sign in button
  • Verify that the user is navigated to the user’s homepage.

Feature File:

This file will have the test scenario which will cover the above steps in Gherkin format:

Feature: Login to Facebook
  In this feature, we will log in to facebook website.
  Scenario: Login with correct credentials.
    Given user navigates to facebook website
    Then user enters the emailId as
    Then user enters the password as abc@123
    Then user clicks on login button
    And user logged in successfully
    And user closes the browser

Step-Definition file:

This file consists of the test steps which are glued to the steps mentioned in the above gherkin language.

public class FacebookLogin {

	WebDriver driver;

	@Given("user navigates to facebook website")
	public void invokeBrowser() {

				"C:/Users/Saurabh Dhingra/workspace/libs/chromedriver2.45/chromedriver.exe");

		driver = new ChromeDriver();




	@Then("user enters the emailId as (.*)")
	public void enterEmailId(String emailId) {

	@Then("user enters the password as (.*)")
	public void enterPassword(String password) {

	@Then("user clicks on login button")
	public void click_login_button() {


	@Then("user logged in successfully")
	public void verifyLoginIsSuccessful() {
		System.out.println("Logged in successful");

	@And("user closes the browser")
	public void closeBrowser() {

PS: For any questions, queries or feedback. Feel free to write us at or

Saurabh Dhingra

About the Author

Saurabh Dhingra

Follow Saurabh Dhingra: