At 1.5–3 years, Cucumber interview questions test whether you can build and run a BDD framework: its architecture, API scenarios with REST Assured, parallel execution, Extent reports and custom parameter types.
Mid-Level Questions
How do you implement parallel execution in Cucumber?
Two approaches: 1. TestNG parallel DataProvider — override scenarios() in the runner with @DataProvider(parallel=true) — runs each scenario in a separate thread. 2. Maven Surefire parallel methods — configure parallel=methods and threadCount in the plugin. Both require ThreadLocal<WebDriver> in DriverManager to prevent driver sharing between threads.
Why is ThreadLocal necessary for parallel Cucumber execution?
In parallel execution, multiple threads run simultaneously. A static WebDriver field is shared — Thread A might call driver.quit() while Thread B is still using it. ThreadLocal gives each thread its own isolated WebDriver instance. getDriver() always returns the current thread's driver. remove() in @After hook prevents memory leaks.
How do you integrate RestAssured with Cucumber?
Write feature files with API-focused Gherkin (Given base URL, When I send GET to endpoint, Then status should be 200). Create API step definition classes that use RestAssured's given-when-then DSL internally. Store the Response object in a TestContext class shared via PicoContainer. Assert response fields in Then steps.
What is the ExtentCucumberAdapter?
extentreports-cucumber7-adapter is a Cucumber plugin that automatically generates Extent Reports from Cucumber test results. Add it to @CucumberOptions plugin array. Configure via extent.properties. It creates feature-level and scenario-level nodes, captures step status, and attaches screenshots from scenario.attach() calls.
What is the difference between @Before(order=1) and @Before(order=2)?
In Cucumber hooks, lower order value = runs FIRST. @Before(order=1) runs before @Before(order=2). For @After hooks, the order is reversed: higher value = runs FIRST. This lets you control the sequence: open browser (order 1), navigate to URL (order 2), then in teardown: screenshot (order 2), quit browser (order 1).
How do you implement Allure reports with Cucumber?
Add allure-cucumber7-jvm dependency. Add the plugin: plugin={"io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm"} to @CucumberOptions. Annotate step defs or hooks with @Step, @Attachment, @Feature, @Story. Run tests, then: allure serve target/allure-results to view the interactive report.
What is the difference between AbstractTestNGCucumberTests and CucumberOptions?
AbstractTestNGCucumberTests is the TestNG base class for the runner — it bridges TestNG and Cucumber, making each scenario a TestNG test method and enabling TestNG's parallel execution, listeners, and reporting. @CucumberOptions is a configuration annotation that tells Cucumber where to find features, step defs, and how to report.
How do you skip a scenario programmatically in Cucumber?
In a @Before hook: throw a cucumber.api.PendingException to mark as Pending, or use Assume.assumeTrue (JUnit) / SkipException (TestNG) to skip. Add tags like @skip or @wip and exclude them in the runner: tags = "not @skip". In CI, specific environments can run different tag expressions.
How do you handle authentication tokens in API BDD tests?
Store the token in TestContext after a login step. Subsequent steps inject TestContext and retrieve the token to set it in the Authorization header. Example: context.setToken(response.jsonPath().getString("token")); then: given().header("Authorization","Bearer "+context.getToken()). This mimics real user authentication flow.
What is the cucumber.properties file?
cucumber.properties (in src/test/resources) provides system-level Cucumber configuration: cucumber.publish.enabled=false (disable automatic publish), cucumber.filter.tags=@smoke (default tag filter), cucumber.junit-platform.naming-strategy=long. Settings in this file apply globally without needing command-line args.
How do you generate a Cucumber HTML report?
Add to @CucumberOptions plugin: html:target/cucumber-reports/report.html. Cucumber generates a self-contained HTML file with feature/scenario status, step details, duration, and optional screenshots. For richer reports, use extent-reports-cucumber7-adapter (Extent Reports) or allure-cucumber7-jvm (Allure).
What is Cucumber's @DocString?
DocString (triple quotes in Gherkin) passes multi-line text content to a step. Example: When I send request body: followed by """ { "name": "Ravi" } """. In the step def: @When("I send request body:") public void sendBody(String body) { ... }. Used for JSON payloads, XML, or SQL queries in API tests.
How do you read test data from Excel in Cucumber?
Use Apache POI in the step def or a TestDataReader utility. @Given("I login with credentials from row {int}") reads row from Excel: XSSFWorkbook wb = new XSSFWorkbook(file); Row row = sheet.getRow(rowNum); String user = row.getCell(0).getStringCellValue(). Alternatively, use Scenario Outline with an Examples table populated from the sheet.
What is the @CucumberOptions strict option?
In Cucumber v7+, strict mode is the default — undefined or pending steps cause the build to fail. In earlier versions, strict=false allowed the suite to pass even with undefined steps. Setting strict=true is best practice in CI to ensure all steps have implementations and prevent silent test gaps.
What is a Feature file's narrative (As a / I want / So that)?
The three lines after the Feature keyword are the user story narrative: As a [role] / I want [feature] / So that [benefit]. They are purely documentation — Cucumber ignores them during execution. They help team members understand the purpose and user perspective of the feature without reading all scenarios.
How do you test file upload using Cucumber?
Write a Gherkin step: When I upload the file "invoice.pdf". In the step def: find the file input element with driver.findElement(By.id("fileInput")), call sendKeys with the absolute file path. For non-standard upload dialogs, use Robot class or AutoIT. The file path can be parameterised from the Gherkin step or config.
How do you handle database verification in Cucumber?
Write Then steps that query the database: Then the user should be saved in the database. In the step def, use JDBC: Connection conn = DriverManager.getConnection(url, user, pass); PreparedStatement ps = conn.prepareStatement("SELECT * FROM users WHERE email=?"); ps.setString(1, email); ResultSet rs = ps.executeQuery(); Assert.assertTrue(rs.next()).
What is the purpose of multiple runner classes?
Different runners target different scenarios: SmokeRunner — tags="@smoke" for fast PR checks (5-10 mins). RegressionRunner — tags="@regression" for nightly full suite (1-2 hours). SanityRunner — tags="@sanity" for post-deployment verification. FailedRunner — features="@target/rerun.txt" for re-running failures.
How do you handle date-based test data in Cucumber?
Avoid hardcoded dates in feature files. Options: 1. Use relative expressions in Gherkin: "today", "tomorrow", "+7 days" and resolve in step defs with LocalDate.now().plusDays(7). 2. Use a custom ParameterType that parses relative date expressions. 3. Pass date format in Examples table and format in the step def.
What is the JSON plugin output used for?
The JSON plugin (plugin={"json:target/report.json"}) generates a structured JSON file with full test run data. This JSON is consumed by: Jenkins Cucumber Reports plugin (interactive HTML in Jenkins), Extent Reports (via its JSON adapter), Cluecumber Maven plugin, and test management systems like Xray, Zephyr, and TestRail for importing results.
FAQs
How do you run Cucumber scenarios in parallel?
With TestNG, extend AbstractTestNGCucumberTests and override scenarios() with @DataProvider(parallel = true); with JUnit 5, use the Cucumber JUnit Platform engine with parallel configuration. Keep WebDriver per thread.