Automation Testing Cucumber Guide
The complete guide to Cucumber BDD — what BDD is, Gherkin keywords, project structure, hooks and tags, when Cucumber helps, common mistakes and tips for step reuse.
9 programs
Choose the best training program according to your career.
Improve the performance of your business with our innovative Industrial Training Program.
Read More →
Our instructor-led training classes are designed to make you an expert.
Read More →
Real-life case studies are a great way to demonstrate your practical knowledge.
Read More →
Explore blogs, latest technologies and industry updates with practical examples.
Read More →Browse all available training programs and choose the right one for your career.
Read More →Know more about who we are and what we stand for.
Discover our mission to equip individuals with essential IT skills and industry expertise.
Read More →Learn, practice and plan your career — bilkul free.
Book a free video counselling session and pick the right course for you.
Read More →Download the Cucumber BDD guide PDF from Uncodemy: Gherkin, feature files, step definitions, scenario outlines, hooks and tags.
This page offers Uncodemy's Cucumber guide as a PDF download. Cucumber supports behaviour-driven development by letting teams write tests in plain language that business people can read, and then linking each step to automation code. The guide covers Gherkin, feature files, step definitions, scenario outlines, hooks and tags.
Three quick-access entry points into the same Cucumber BDD guide PDF: the full guide, the feature file + step definition code pack, and the Gherkin good vs weak wording reference. All PDFs on this page are free to download. No form is required.
The complete guide to Cucumber BDD — what BDD is, Gherkin keywords, project structure, hooks and tags, when Cucumber helps, common mistakes and tips for step reuse.
A complete Gherkin feature file (login with Background, @smoke tag and Scenario Outline) plus the Java step definitions that wire each step to a page object.
Weak vs better step wording examples, guidance on writing declarative scenarios, plus Cucumber vs plain test frameworks comparison and step definition reuse tips.
All three download buttons open the same Cucumber BDD guide PDF file. By downloading, you agree to our Privacy Policy. These PDFs are study material only — not a certificate or job guarantee.
Behaviour-driven development, or BDD, is a way of working in which business people, developers and testers agree on examples of behaviour before building a feature, and write those examples in a shared, structured language. Cucumber is a tool that reads these examples, written in a language called Gherkin, and runs them against the application by calling automation code. The value is mostly in the conversation: the examples force the team to agree on what the feature should do. A side benefit is living documentation that stays accurate because it is executed. Cucumber is not a replacement for good test design, and for purely technical tests a plain framework is often simpler.
| Keyword | Meaning |
|---|---|
| Feature | Names the capability and describes its purpose |
| Background | Steps shared by all scenarios in the file |
| Scenario | One example of behaviour |
| Scenario Outline with Examples | A template scenario run with several data rows |
| Given | The starting context |
| When | The action taken |
| Then | The expected outcome |
| And, But | Continue the previous step type |
| @tag | Labels scenarios or features for filtering |
A readable specification in Gherkin. Business and technical people can both understand it.
@login
Feature: Login
As a registered user
I want to sign in
So that I can see my dashboard
Background:
Given the user is on the login page
@smoke
Scenario: Successful login
When the user enters email "test.user@example.com" and a valid password
And clicks the login button
Then the dashboard page is displayed
Scenario Outline: Failed login messages
When the user enters email "<email>" and password "<password>"
And clicks the login button
Then the error message "<message>" is displayed
Examples:
| email | password | message |
| test.user@example.com | wrong-pass | Invalid credentials |
| | | Email is required |
Each Gherkin step matches a method through an expression. Illustrative structure; the page object is assumed to exist.
import io.cucumber.java.en.*;
import org.junit.Assert;
public class LoginSteps {
private final LoginPage loginPage = new LoginPage(Hooks.driver);
@Given("the user is on the login page")
public void userIsLoginPage() {
loginPage.open();
}
@When("the user enters email {string} and password {string}")
public void userEnterCredentials(String email, String password) {
loginPage.enterEmail(email);
loginPage.enterPassword(password);
}
@When("the user clicks the login button")
public void clicksLogin() {
loginPage.submit();
}
@Then("the error message {string} is displayed")
public void errorIsDisplayed(String expected) {
Assert.assertEquals(expected, loginPage.errorText());
}
}
| Item | Purpose |
|---|---|
src/test/resources/features |
Feature files |
steps package |
Step definition classes |
pages package |
Page objects wrapping UI locators and actions |
| hooks class | Before and After hooks for driver setup and teardown |
| runner class | Configures which features, tags and reports run |
| config and utilities | Environment settings, readers and helpers |
Good scenarios describe behaviour from the user's point of view, not implementation. A step such as the user clicks the button with id submit-bttn ties the example to the interface and breaks whenever the design changes. A step such as the user submits the login form expresses intent and leaves the detail to the step definition. Keep scenarios short, with one clear outcome, and use concrete examples rather than abstract statements. Avoid long lists of steps that read like a manual script; if a scenario needs fifteen steps, it is probably testing too much.
| Weak | Better |
|---|---|
| Given the user types abc in the field with id user | Given a registered user has an account |
| When the user clicks the third button on the page | When the user submits the login form |
| Then the div with class error appears | Then the error message Invalid credentials is displayed |
| Aspect | Cucumber | TestNG or JUnit alone |
|---|---|---|
| Readability for non-programmers | High | Low |
| Setup effort | More: feature files plus step definitions | Less |
| Collaboration value | High if the business reviews scenarios | Mostly for developers and testers |
| Maintenance risk | Duplicate or vague steps if not managed | Fewer layers to maintain |
Ready to build Cucumber suites that business and engineering both trust? Explore Uncodemy's Software Testing course or book a free demo and learn from industry trainers.