🥒 Cucumber — BDD & Gherkin Test Automation

Cucumber — BDD & Gherkin Test Automation: Cucumber is a bridge that connects Gherkin scenarios written in natural language (`Given/When/Then`) to real Java code via step definiti

Cucumber is a bridge that connects Gherkin scenarios written in natural language (`Given/When/Then`) to real Java code via step definitions — like a bilingual contract: one column has a plain sentence everyone understands, the other has the technical clause that executes it, and the two match line by line. But if you can write the test directly in Java with JUnit5, why add a Gherkin layer and create extra work? Because pure JUnit5 code can only be read by developers; with Gherkin the business analyst, product owner, and QA share the same scenario as a single "source of truth," reducing misunderstandings. On the Java side Cucumber works with both the JUnit5 and TestNG runners; this is the Java equivalent of `behave` in Python or `cucumber-js` in JS. For a QA engineer the real gain is communication: when an acceptance criterion is written in Gherkin it becomes both living documentation and a test, preventing silent coverage gaps of the "this was the requirement but the test checks something else" kind.

Gherkin Syntax — Feature File

login.feature — Gherkin example

Micro Lab: Code practice

Replace the TODO line with the critical line from the expected solution. This is not a real runtime; the goal is to reinforce writing the correct structure in a controlled way.

How Does a .feature File Define a Test WITHOUT Any Java Code?

The `Feature: User Login` title summarizes in plain language WHICH business capability the file tests — even a non-technical reader (PO, analyst) understands it.

`Background: Given browser is open on the login page` runs AUTOMATICALLY before EVERY scenario — you don't need to REPEAT the same "open the browser first" step in every Scenario.

Tags like @smoke @critical GROUP scenarios…

Tags like `@smoke @critical` GROUP scenarios — in CI, `--tags "@smoke"` lets you run only the critical scenarios without waiting for the whole suite.

Scenario Outline + the Examples table…

`Scenario Outline` + the `Examples` table run the SAME steps REPEATEDLY with 3 different data rows (admin/user1/wrong) — you get data-driven testing without duplicating code.

Step Definitions — Gherkin → Java

LoginSteps.java — Step Definitions