DEV Community

Cover image for TestFly Part 5: BDD Testing with Cucumber 7, BaseCucumberSteps & @retryable Tags
Hakan GÜL
Hakan GÜL

Posted on Originally published at hakangul.lovable.app

TestFly Part 5: BDD Testing with Cucumber 7, BaseCucumberSteps & @retryable Tags

BDD with Cucumber 7 in TestFly

TestFly integrates with Cucumber 7 out of the box with zero boilerplate:

  • Automatic Driver Lifecycle: Managed via CucumberHooks in io.testfly.cucumber.
  • Step Timeline Logging: Streamed directly into the HTML report via CucumberStepLogger.
  • Automatic Screenshots: Captured and embedded on failure in both reports.
  • Per-Scenario Retry: Configured with @retryable or @retryable=N tags.

1. Runner Class (BaseCucumberTest)

package com.yourcompany.bdd;

import io.cucumber.testng.CucumberOptions;
import io.testfly.cucumber.BaseCucumberTest;

@CucumberOptions(
    features = "src/test/resources/features",
    glue     = {"com.yourcompany.bdd.steps", "io.testfly.cucumber"},
    plugin   = {"pretty", "io.testfly.cucumber.CucumberStepLogger"}
)
public class CucumberRunner extends BaseCucumberTest {}
Enter fullscreen mode Exit fullscreen mode

2. Step Definitions with BaseCucumberSteps

package com.yourcompany.bdd.steps;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import io.cucumber.java.en.Then;
import io.testfly.cucumber.BaseCucumberSteps;
import org.openqa.selenium.By;

public class LoginSteps extends BaseCucumberSteps {

    @Given("the user is on the login page")
    public void onLoginPage() {
        open("/login");
    }

    @When("they login as {string} with password {string}")
    public void login(String username, String password) {
        find(By.id("username")).type(username);
        find(By.id("password")).type(password);
        find(By.id("submit")).click();
    }

    @Then("the dashboard is visible")
    public void dashboardVisible() {
        assertThat(By.id("dashboard")).isVisible(); // auto-retrying assertion
    }
}
Enter fullscreen mode Exit fullscreen mode

3. Per-Scenario Retry Tag

@retryable=2
Scenario: Flaky payment gateway widget
  Given the user is on the payment screen
  When they submit payment details
  Then the transaction should be confirmed
Enter fullscreen mode Exit fullscreen mode

Top comments (0)