BDD with Cucumber — End-to-End Tutorial (2026)
Ship your first Cucumber BDD suite in a day. Feature files, step definitions, hooks, tags, and CI wiring for Java, JS, and Python. Includes when BDD hurts and how to avoid the Gherkin trap.

Last updated 2026-07-20 · 14 min read · By Avinash Kamble, reviewed by Priyanka G.
Cucumber done right closes the gap between product, dev, and QA. Cucumber done wrong is Selenium tests with extra YAML. This tutorial ships you a working BDD suite in Java, JS, or Python and calls out the four mistakes that make teams abandon Cucumber after six months.
Key takeaways
- Working Cucumber setup in 15 minutes across 3 languages.
- Gherkin best practices from real product-QA collaboration.
- Tags, hooks, and parallel execution.
- When BDD adds cost without value — how to spot it early.
1. When BDD is worth it (and when it isn't)
Worth it when product/BA/QA collaborate on scenarios before code exists. Not worth it when QA writes both the feature file and the step definitions with no product involvement — you added indirection for nothing.
2. Your first feature file
Feature: Checkout coupon
As a shopper I want to apply coupons so I can save money
Scenario: Expired coupon is rejected
Given I have a cart with one item
And the coupon "EXPIRED2025" has expired
When I apply the coupon on checkout
Then I see the message "This coupon has expired"
And the cart total is unchanged3. Step definitions in JavaScript (Cucumber-JS + Playwright)
import { Given, When, Then } from '@cucumber/cucumber';
import { expect } from '@playwright/test';
Given('I have a cart with one item', async function () {
await this.api.seedCart(this.user, [{ sku: 'BOOK-1', qty: 1 }]);
});
When('I apply the coupon on checkout', async function () {
await this.page.goto('/checkout');
await this.page.getByLabel('Coupon').fill(this.coupon);
await this.page.getByRole('button', { name: 'Apply' }).click();
});
Then('I see the message {string}', async function (msg: string) {
await expect(this.page.getByRole('alert')).toHaveText(msg);
});4. Step definitions in Java (Cucumber-JVM + Selenium)
@Given("I have a cart with one item")
public void iHaveACart() { api.seedCart(user, "BOOK-1", 1); }
@When("I apply the coupon on checkout")
public void iApplyCoupon() {
driver.get(BASE + "/checkout");
driver.findElement(By.id("coupon")).sendKeys(coupon);
driver.findElement(By.id("apply")).click();
}
@Then("I see the message {string}")
public void iSeeMessage(String msg) {
assertEquals(msg, driver.findElement(By.cssSelector("[role=alert]")).getText());
}6. Four Cucumber traps to avoid
- Imperative Gherkin ("I click the button") — write declarative business intent instead.
- Step explosion — dedupe and parameterize.
- Shared world state — leaks between scenarios. Reset in hooks.
- No product participation — if only QA reads .feature files, delete Cucumber.
Pair with the test automation complete guide and see our SpecFlow tutorial for C# for the .NET flavor.
Frequently asked questions
1.Cucumber vs Playwright Test — which for BDD?
2.Is Gherkin still readable at 500 scenarios?
3.Can I use Cucumber for API tests?
4.How do I run Cucumber in GitHub Actions?
Practice these questions
Rehearse Selenium and Playwright automation questions covering framework design, waits, locators and CI/CD.
Was this article helpful?
More from BDD Cucumber
Gherkin, step definitions, Cucumber with Java/JS.
- Automation TestingSpecFlow C# BDD Tutorial: Complete 2026 Guide
- Automation TestingBDD Testing with Cucumber: Beginner Guide (2026)
- AI in TestingChatGPT Gherkin Scenarios in 2026: The Complete BDD Playbook (Prompts, Anti-Patterns & FAQ)
Keep building your QA edge
Pillar guides- Automation QA Engineer RoleSoftwareTestPilot's Automation QA role pageAutomation QA Engineer job scope, tools, salary, and hiring pipeline.
- QA Skills Hubstructured learning tracks for testersStructured skill tracks — Selenium, Playwright, Cypress, API, JMeter, SQL, Java, Python for testers.
- QA & Testing GlossaryQA terminology explained in plain English500+ software testing terms defined — from ISTQB vocabulary to CI/CD, AI testing, and framework jargon.
Continue reading

Playwright Locator Best Practices (2026) — The Only Guide You Need
11 min read
How to Migrate a Postman Collection to Playwright API Tests (2026 Guide)
12 min read
Why Every QA Engineer Must Master CI/CD Pipelines in 2026 (Or Risk Obsolescence)
12 min readRelated concepts, tools & standards around Automation Testing
A quick reference of the people, companies, frameworks and technologies most often mentioned alongside Automation Testing in real QA teams — useful when you're mapping a learning path, preparing for interviews, or scoping a new project.
Join the QA Community
Connect with fellow testers, share job leads, and get career advice.
Stop Reinventing the Wheel. Upgrade Your QA Arsenal.
Take your testing skills from beginner to Lead Engineer. Supercharge your daily workflow with our premium digital resources.
- Ready-to-use testing strategy templates
- Advanced API & UI automation guides
- ⏱️ Save 10+ hours a week on test planning
Discussion
Ask a question, share your experience, or correct us. Be kind — real people are reading.