BDD with Cucumber 7 in TestFly
TestFly integrates with Cucumber 7 out of the box with zero boilerplate:
-
Automatic Driver Lifecycle: Managed via
CucumberHooksinio.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
@retryableor@retryable=Ntags.
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 {}
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
}
}
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
Top comments (0)