Content ITV PRO
This is Itvedant Content department
Gherkin Syntax
Learning Outcome
4
Write clear and maintainable Gherkin tests
3
Separate preconditions, actions, and outcomes
2
Convert requirements into test scenarios
1
Create BDD scenarios using Gherkin keywords
5
Organize scenarios into feature files
Gherkin Syntax
Basic knowledge of software testing concepts
Familiarity with requirements or user stories
Understanding of test cases (input, steps, expected result)
Basic idea of Behavior-Driven Development (BDD)
Ability to write simple, clear English statements
Basic awareness of automation tools like Cucumber
RECALL
Why do we use Gherkin syntax?
We use Gherkin syntax for the following reasons:
To describe software behavior in simple, human-readable language
To bridge communication between business stakeholders, testers, and developers
To convert requirements into structured test scenarios
To support Behavior-Driven Development (BDD) practices
To make test cases clear, consistent, and easy to understand
To enable automation testing by linking scenarios with tools like Cucumber
To ensure everyone has a shared understanding of expected system behavior
What is Gherkin?
Gherkin is a structured, plain-English language used to write test scenarios in Behavior-Driven Development (BDD).
It describes how software should behave in a way that both technical (developers/testers) and non-technical (business users) people can understand.
Features of Gherkin
Why Tags are used:
To group tests (e.g., @Smoke, @Regression)
To run only selected scenarios
To avoid running all tests every time
A tag in Cucumber is used to mark and filter test scenarios for execution.
What is pom.xml?
Parameters and expressions in steps
Parameters and expressions allow step definitions to accept dynamic values from Gherkin steps instead of hardcoded data.
@When("user enters {string} and {string}")
public void enterCredentials(String username, String password) {
System.out.println(username);
System.out.println(password);
}"admin" → username
"1234" → password
Step definition:
Parameters
@When("user adds {int} and {int}")
public void add(int a, int b) {
System.out.println(a + b);
}Example:
Expressions
Expressions define how Cucumber identifies and captures values from steps.
What is pom.xml?
Running Tests Using Tags
Tags are used to select and run specific scenarios from a large set of tests written in Gherkin.
Add Tags in Feature File
What is pom.xml?
Running Tests Using Tags
Tags are used to select and run specific scenarios from a large set of tests written in Gherkin.
Configure Tags in Test Runner
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/features",
glue = "stepDefinitions",
tags = "@Smoke"
)
public class TestRunner {
}This runs only Smoke tests
Using JUnit
What is pom.xml?
Tag Execution Options
✔ Run single tag
tags = "@Smoke"
✔ Run multiple tags (AND condition)
tags = "@Smoke and @Regression"
✔ Run either tag (OR condition)
tags = "@Smoke or @Regression"
✔ Exclude tag
tags = "not @Smoke"
Summary
4
Work with JUnit / TestNG for execution control
3
Improve test control and organization
2
Tags help run specific tests only
1
Hooks (@Before, @After) → handle setup and cleanup (e.g., browser open/close)
Quiz
Which annotation is used for teardown in Cucumber?
A.@Before
B.@After
C.@Test
D.@RunWith
Which annotation is used for teardown in Cucumber?
A.@Before
B.@After
C.@Test
D.@RunWith
Quiz-Answer
By Content ITV