Step definitions are Java methods that execute the steps written in your feature files. Each Gherkin step (Dado, Cuando, Entonces) must have a corresponding step definition that implements the actual test logic.Step definitions are stored in:
Here’s the actual step definition file from our framework:
package org.btg.practual.stepDefinitions;import io.cucumber.java.es.Dado;import io.cucumber.java.es.Cuando;import io.cucumber.java.es.Entonces;public class GeneracionReporteSteps { @Dado("el usuario ingresa a la web de Chronos") public void el_usuario_ingresa_a_la_web_de_chronos() { // Write code here that turns the phrase above into concrete actions System.out.println("Step: el usuario ingresa a la web de Chronos"); } @Cuando("ingrese los datos del reporte {string} para la compañia {string} segun la fecha {string}") public void ingrese_los_datos_del_reporte_para_la_compañia_segun_la_fecha(String reporte, String compania, String fecha) { // Write code here that turns the phrase above into concrete actions System.out.println("Step: ingrese los datos del reporte " + reporte + " para la compañia " + compania + " segun la fecha " + fecha); } @Entonces("se genera el reporte {string} de manera exitosa") public void se_genera_el_reporte_de_manera_exitosa(String reporte) { // Write code here that turns the phrase above into concrete actions System.out.println("Step: se genera el reporte " + reporte + " de manera exitosa"); }}
This step definition is located at: src/test/java/org/btg/practual/stepDefinitions/GeneracionReporteSteps.java
Do NOT use the English annotations (@Given, @When, @Then) when working with Spanish Gherkin. Use the Spanish equivalents from io.cucumber.java.es package.
Use {string} in the annotation and add a String parameter to the method:
@Cuando("ingrese los datos del reporte {string} para la compañia {string} segun la fecha {string}")public void ingrese_los_datos_del_reporte_para_la_compañia_segun_la_fecha(String reporte, String compania, String fecha) { System.out.println("Step: ingrese los datos del reporte " + reporte + " para la compañia " + compania + " segun la fecha " + fecha);}
When the feature file contains:
Cuando ingrese los datos del reporte "417" para la compañia "compañia 1" segun la fecha "2026-02-01"
// Gherkin: Dado el usuario ingresa a la web de Chronos@Dado("el usuario ingresa a la web de Chronos")public void el_usuario_ingresa_a_la_web_de_chronos() { }// Gherkin: Cuando ingrese los datos del reporte "<report>" para la compañia "<company>" segun la fecha "<report_date>"@Cuando("ingrese los datos del reporte {string} para la compañia {string} segun la fecha {string}")public void ingrese_los_datos_del_reporte_para_la_compañia_segun_la_fecha(String reporte, String compania, String fecha) { }// Gherkin: Entonces se genera el reporte "<report>" de manera exitosa@Entonces("se genera el reporte {string} de manera exitosa")public void se_genera_el_reporte_de_manera_exitosa(String reporte) { }
While method names follow these conventions, you can technically name them anything. However, following the convention makes code more maintainable and searchable.
@Dado("el usuario ingresa a la web de Chronos")public void el_usuario_ingresa_a_la_web_de_chronos() { // Real implementation would: // 1. Initialize the WebDriver // 2. Navigate to the Chronos URL // 3. Wait for page to load driver.get("https://chronos.btg.com"); wait.until(ExpectedConditions.titleContains("Chronos"));}
@Cuando("ingrese los datos del reporte {string} para la compañia {string} segun la fecha {string}")public void ingrese_los_datos_del_reporte_para_la_compañia_segun_la_fecha(String reporte, String compania, String fecha) { // Real implementation would: // 1. Find and fill the report field // 2. Select the company from dropdown // 3. Enter the date // 4. Submit the form reportField.sendKeys(reporte); companyDropdown.selectByVisibleText(compania); dateField.sendKeys(fecha); submitButton.click();}
Cuando ingrese los datos del reporte "417" para la compañia "compañia 1" segun la fecha "2026-02-01"
Step definition:
@Cuando("ingrese los datos del reporte {string} para la compañia {string} segun la fecha {string}")public void ingrese_los_datos_del_reporte_para_la_compañia_segun_la_fecha(String reporte, String compania, String fecha)
✅ Match! The text matches exactly when parameters are replaced with {string}.
If Cucumber cannot find a matching step definition, it will show an “Undefined step” error and suggest a stub method to implement.