Cucumber — Step Definition | Code Factory

Cucumber Tutorial Index Page: Link

  • Cucumber doesn’t know how to execute scenarios in feature file alone.
  • It needs a step definition to translate plain text Gherkin steps into actions that will interact with system.
  • When Cucumber executes a step in scenario it will look for matching step definition to execute.
  • A step definition is a small piece of code with a pattern attached to it.
  • The pattern is used to link the step definition to all the matching steps and the code is what cucumber will executes when it sees a Gherkin step.
Feature: Login functionality feature
Scenario: Login functionality with valid data
Given Navigate to login page
When User logged in using username as "user1" and password as "user1
Then Home page should be display
public class stepDefinition {
WebDriver driver;

/* */
static {
/* System.setProperty("webdriver.gecko.driver", "<path to your gecko driver executable>"); */
System.setProperty("webdriver.gecko.driver", "C:\\Users\\CodeFactory\\Downloads\\geckodriver-v0.28.0-win64\\geckodriver.exe");

@Given("^Navigate to login page$")
public void navigate() {
driver = new FirefoxDriver();

@When("^User logged in using username as "user1" and password as "user1"$")
public void login() {

@Then("^Home page should be display$")
public void verifySuccessful() {
String expectedText = "Logout";
String actualText = driver.Findelement(By.linkText("Logout")).getText();
Assert.assertTrue("Login was successful", expectedText.equals(actualText));




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

[Recap] AMA with DOM Chain Global Ambassador Jonah Schulman (August 11, 2021)

Privacera and Starburst Support Launch of Delta Sharing With Open Source-Powered Partnership

How to Make Peter McKeever’s Diamond Chart in ggplot2

What is HAProxy and how to install and configure in Linux

The OEM market will likely struggle to convince

Guest Registration Application

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Code Factory

Code Factory

More from Medium

What Is Regression Testing and How Does It Work? Definition & recommended Tools

Should we automate our exploratory tests ?

Writing Automated Tests in Java Part 2

Environments in Postman