Step Definitions, Glue Code, Parameterization, and Mapping Gherkin to Automation
Learn how human-readable scenarios are connected to executable code and why step design quality matters.
Inside this chapter
- What Step Definitions Do
- Basic Example
- Parameters and Reusability
- Step Design Advice
Series navigation
Study the chapters in order for the clearest path from beginner BDD concepts to advanced automation architecture. Use the navigation at the bottom of each page to move through the full tutorial series.
What Step Definitions Do
Step definitions are the code methods that bind Gherkin steps to automation logic. They are the bridge between the language of behavior and the language of implementation. Each matching step definition interprets the scenario step and runs the corresponding code.
Basic Example
@Given("the user is on the login page")
public void user_is_on_login_page() {
driver.get("https://example.com/login");
}
@When("the user enters valid credentials")
public void user_enters_valid_credentials() {
loginPage.login("student@example.com", "secret");
}
This is where good architecture matters. The step definition should usually call page objects or service helpers rather than contain all low-level logic inline.
Parameters and Reusability
@When("the user searches for {string}")
public void user_searches_for(String keyword) {
searchPage.search(keyword);
}
Parameterized steps reduce duplication and make features more expressive. Advanced teams balance reuse with readability so that steps stay meaningful instead of becoming generic and confusing.
Step Design Advice
Strong step definitions are business-readable, cohesive, and thin. Weak step definitions leak too many implementation details or become giant methods with mixed responsibilities. Keep the behavior description high-level, and push technical details into helper layers.