Cucumber – What is Gherkin

HOME

Feature: Book flight ticket for one-way trip
Scenario:flight ticket for one-way trip from Dublin 

Given I live in Dublin 
And I want to book one way flight ticket from Dublin for 22nd Jan 20
When I search Online 
Then TripAdvisor should provide me options of flight for 22nd Jan 20 
And Cost of my flight should not be more than 50 
And Tickets should be refundable

What is Step Definition?

It is a Java method with an expression, which is used to link it to Gherkin steps. When Cucumber executes a Gherkin step, it will look for a matching step definition to execute.

Feature: Book flight ticket for one-way trip
Scenario: flight ticket for one-way trip from Dublin 
Given  I live in Dublin 
 
@Given ("I live in Dublin") 
public voidVacation()
          {
                   System.out.println("I live in Dublin");
          }

When Cucumber encounters a Gherkin step without a matching step definition, it will print a step definition snippet with a matching Cucumber Expression. We can use this as a starting point for a new step definition.

Scenario: Flight ticket for one-way trip from Dublin 
Given  I live in Dublin

Here, Cucumber didn’t get step definition for the above-mentioned Given step. So, it will provide a snippet as mentioned below:-

@Given ("I live in Dublin")
public void i_live_in_Dublin() {
          // Write code here that turns the phrase above into concrete actions
 
    throw new cucumber.api.PendingException();
}

We are done! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!

3 thoughts on “Cucumber – What is Gherkin

  1. Nice attempt. I was going through your other blogs and saw there is a section for selenium interview questions. Can you add something like that for cucumber. Cheers

    Like

  2. We need to create a Runner file which is used to run the feature file, it is something like below. There will be another tutorial on this topic.@RunWith(Cucumber.class)@CucumberOptions(features = \”src/test/resources/features/Demo.feature\”, tags = \”\”)public class TestRunner {}

    Like

Leave a reply to Pat Cancel reply