Senior Cucumber interview questions are about strategy and scale: when BDD helps and when it hurts, the Screenplay pattern, living documentation and three-amigos sessions, CI/CD for BDD suites, custom plugins and metrics, and BDD across microservices.

Cucumber interview questions by experience: Freshers · 3 years · 5 years

Senior Questions

What is the Screenplay Pattern and why is it better than POM?

POM abstracts locators into page classes but tests still contain sequential procedural steps. Screenplay introduces Actors, Tasks, and Questions. Tests read: actor.attemptsTo(Login.withCredentials(u,p)). Tasks are reusable across tests. Questions make assertions explicit. Benefits: higher abstraction, tests match acceptance criteria, Tasks compose, better error messages, scales to large teams.

What is 'Specification by Example' in BDD?

Specification by Example is the practice of collaboratively creating concrete examples of expected behaviour (as Gherkin scenarios) to serve as both documentation and automated tests. The Three Amigos meeting (BA, Dev, QA) writes these examples before development. They replace traditional test case documents with executable specifications.

What is the Three Amigos session?

A collaborative meeting involving three roles — Business Analyst (defines WHAT), Developer (explains HOW, raises constraints), and QA/SDET (asks edge case questions, writes scenarios). Happens before development of a user story. Produces agreed Gherkin scenarios that are both the requirement spec and the automated acceptance test.

What is declarative vs imperative Gherkin style?

Imperative: describes low-level UI actions — When I click the button with id loginBtn. Declarative: describes business intent — When I log in with valid credentials. Declarative is preferred — it survives UI changes (only step defs change, not scenarios), reads as business language, and focuses on behaviour not implementation.

How do you integrate Cucumber with Spring Boot?

Add cucumber-spring to pom.xml. Create a @CucumberContextConfiguration class annotated with @SpringBootTest. This bootstraps the Spring context. Step definition classes can then use @Autowired to inject Spring beans (services, repositories). Use @LocalServerPort to get the dynamic port for RestAssured tests.

How do you manage test data in a large BDD suite?

Options: Test Data Factory — create objects via APIs before scenarios. Test data isolation — each scenario creates and cleans its own data. Shared reference data — for read-only lookup data. Environment-specific data files. Database seeding with SQL scripts in @Before. Never share mutable data between scenarios — it causes order-dependent failures.

What is the @CucumberContextConfiguration annotation?

It marks a class as the Spring configuration bootstrap for Cucumber. Without it, Cucumber cannot start the Spring ApplicationContext. It is placed on a class in the glue package. Combined with @SpringBootTest (or @ContextConfiguration), it ensures Spring beans are available for injection in step def classes.

How do you implement retry logic in Cucumber?

Option 1: Use the maven-surefire-plugin rerunFailingTestsCount setting. Option 2: Write a custom @CucumberOptions with rerun plugin and a FailedRunner. Option 3: Use a third-party library like cucumber-jvm-parallel-plugin. Option 4: Implement a TestNG IRetryAnalyzer. Always investigate root causes — retry hides flakiness.

How do you handle environment-specific configuration in BDD?

Store environment configs in separate properties files (config-dev.properties, config-staging.properties). Use a ConfigReader that reads a system property: String env = System.getProperty("env","dev"). Load the matching file. Run with: mvn test -Denv=staging. Feature files and step defs don't change — only the config differs.

What is Serenity BDD?

Serenity BDD (formerly Thucydides) is an enhanced BDD framework built on top of Cucumber/JBehave. It provides: richer HTML reports with narrative, Screenplay pattern support, WebDriver management, REST client, and test evidence capture. It is more feature-rich than plain Cucumber but has a steeper learning curve.

How do you test accessibility with Cucumber?

Write scenarios: Then the page should meet WCAG 2.1 AA accessibility standards. In step defs, use Axe-core (axe-selenium-java): Results results = new Axe().call(driver); Assert.assertTrue(results.violationFree()); Capture violations in the report. Run accessibility checks in @After hooks for all scenarios or specific tagged scenarios.

What is Behaviour-Driven Infrastructure (BDI)?

BDI applies BDD concepts to infrastructure testing. Tools: Terraform tests with Gherkin, InSpec (serverspec with Gherkin-like syntax), Cucumber + Ansible tests. Example: Given a server is provisioned, When I check the firewall rules, Then port 22 should be closed. Relevant for DevOps/Platform Engineering SDETs.

How do you prevent test pollution between scenarios?

1. Each scenario sets up its own data in @Before or Background steps. 2. @After cleans up created data (delete records, reset state). 3. Use unique data per run (timestamps in usernames). 4. Use transaction rollback for database tests. 5. Use Docker containers for isolated environments. 6. Never share mutable state via static fields.

What is Cucumber's @ParameterType and when do you use it?

@ParameterType defines a custom Cucumber Expression type. Example: @ParameterType("active|inactive") public Status status(String s) { return Status.valueOf(s.toUpperCase()); } Then use in steps: @When("I set the account to {status}"). This improves type safety, makes steps more readable, and centralises transformation logic.

How do you generate living documentation from Cucumber?

Use Pickles, Relish, or Serenity BDD to generate documentation websites from .feature files. Pickles converts feature files to HTML/JSON/DHTML. The documentation stays in sync with the code because it IS the code (feature files are the source). Publish to Confluence or internal wiki. Share with stakeholders after each sprint.

What is the difference between Cucumber and JBehave?

Both are BDD frameworks for Java. Cucumber: uses .feature files with Gherkin, step annotations, widely adopted, excellent tooling. JBehave: uses story files, step annotations with different syntax, older, less popular. Cucumber is preferred for new projects due to better IDE support, community, and documentation.

How do you handle asynchronous operations in BDD tests?

Use explicit waits in step defs: WebDriverWait.until(condition). For API scenarios with async processing: poll with retries until the expected state. For event-driven systems: use @After to clean up and @Before to wait for system readiness. Avoid fixed Thread.sleep — use condition-based waiting.

What is a Cucumber Expressions ambiguity and how do you fix it?

Ambiguity occurs when two step def methods match the same Gherkin step. Example: two methods with @Given("I am logged in") and @Given("I am {string}"). Cucumber throws AmbiguousStepDefinitionsException. Fix: make expressions more specific, rename one of them, or move to a different glue package and adjust runner configuration.

How do you track BDD test coverage against user stories?

Link scenarios to user story IDs in tags: @JIRA-1234. Use a test management tool like Xray or Zephyr to import Cucumber results and map to JIRA stories. Track: how many acceptance criteria have passing scenarios, how many stories have 0 automation. Generate coverage reports in CI. Review with the team in sprint reviews.

What are anti-patterns in BDD to watch out for?

1. UI-coupled scenarios — steps describe clicks, not behaviour. 2. Giant scenarios — 20+ steps with multiple behaviours. 3. Scenario dependencies — tests pass only in a specific order. 4. Shared mutable state — scenarios pollute each other's data. 5. Technical language in Gherkin — developers write steps for developers not business. 6. Not doing Three Amigos — writing BDD tests after development (just translating test cases).

Advertisement

Expert Questions

How do you design a BDD framework for a team of 10+ SDETs?

Modular structure: separate modules for core (driver, config, DI), pages, step-defs, and features. Enforce POM strictly — no raw driver calls in step defs. Use PicoContainer for DI. Define a step def naming convention (one class per feature area). Use multiple runners (smoke, regression, api). Set up branch-based CI tagging. Hold monthly framework guild meetings.

What is Contract Testing and how does it relate to BDD?

Contract testing verifies that two microservices can communicate as expected. Consumer-driven contracts (Pact) define what the consumer expects from the provider. In BDD: write Gherkin scenarios that describe the expected API interaction. The provider verifies the contract without the consumer running. Prevents integration failures without needing full integration tests.

How do you implement BDD for event-driven microservices?

Write scenarios that describe events: Given event X is published, When service Y processes it, Then state Z should exist. In step defs: publish events to Kafka/SQS, use Awaitility to poll for the expected state. For consumer testing: use Embedded Kafka or Testcontainers. Contract test event schemas with Pact or Confluent Schema Registry.

What is Serenity BDD vs plain Cucumber?

Serenity adds: automatic WebDriver management, Screenplay pattern support, richer reports with narrative and evidence, test coverage metrics against requirements, and REST client integration. Cucumber is simpler and more flexible. Choose Serenity for large teams needing rich reports and Screenplay. Choose plain Cucumber for smaller teams or when you want full control.

How do you handle BDD in a CI/CD pipeline with quality gates?

Quality gates: 1. Smoke suite passes before merging to main. 2. Regression suite passes before deployment to staging. 3. Sanity suite passes before production deployment. Metrics tracked: pass rate, flakiness rate, execution time. Pipeline fails if: pass rate < 95%, any undefined steps, execution time > threshold. Dashboard shows trends over time.

How do you measure the ROI of BDD?

Metrics: bugs found before production (BDD catch rate vs production defects), regression detection time (how quickly suite catches regressions), documentation value (does the team use feature files as requirements?), maintenance cost (hours/sprint fixing broken tests), stakeholder alignment (reduced requirement misunderstanding). ROI = (bug cost prevented) / (automation investment).

What is Awaitility and when do you use it in BDD?

Awaitility is a Java library for testing asynchronous operations. await().atMost(10, SECONDS).pollInterval(500, MILLISECONDS).until(() -> condition). Use in BDD when testing event-driven systems, async APIs, or UI elements that take time to appear. It replaces Thread.sleep with condition-based polling and produces informative timeout messages.

How do you do visual regression testing in BDD?

Write scenarios: Then the login page should match the approved visual baseline. In step defs, use Applitools Eyes: eyes.check("login page", Target.window()); Applitools uses AI to compare against baselines and detect visual changes. Or use Percy/Backstop for simpler pixel-based comparison. Integrate in CI to catch visual regressions in PR checks.

What is the role of Product Owner in BDD?

PO defines business rules and acceptance criteria, writes or reviews Gherkin scenarios in Three Amigos, signs off on scenarios as the definition of done for a user story, and uses living documentation (feature files) to verify implemented behaviour. PO should be able to read and understand all Gherkin scenarios without technical knowledge.

How do you prevent BDD from becoming 'just another test layer'?

BDD becomes just a test layer when: scenarios are written after development (not before), developers aren't involved, Gherkin is written in technical language, Three Amigos doesn't happen. Prevention: involve BA and Dev in scenario writing, review scenarios in sprint planning, check that scenarios match acceptance criteria, reject scenarios with imperative/technical language in code review.

What is a Custom Cucumber Plugin and how do you create one?

A Custom Plugin implements EventListener and registers handlers for Cucumber events: TestStepStarted, TestStepFinished, TestCaseStarted, TestRunFinished, etc. Register in @CucumberOptions plugin array with the fully qualified class name. Use cases: custom reporting, timing metrics, Slack notifications on completion, custom log format.

How do you handle multi-tenant applications in BDD?

Parameterize tenant in scenario tags or Examples: @tenantA, @tenantB. Use tenant-specific config files with different base URLs and credentials. In BeforeAll/@Before, read tenant from tag: scenario.getTags(). Initialise tenant-specific data factories. Run each tenant's scenarios in parallel. Use tenant isolation in test data to prevent cross-contamination.

What is Behavior-Driven Security Testing?

Writing BDD scenarios for security requirements: Given a user is not authenticated, When they access /admin, Then they should receive 403 Forbidden. Or: Given I inject SQL in the username field, When I submit the login form, Then the application should not be vulnerable. Use OWASP ZAP API in step defs for automated security scanning triggered from Gherkin.

How do you version feature files alongside the application code?

Feature files live in the same Git repository as the application code. When a feature changes: update the feature file, update step defs, update page objects in the same PR/commit. Branch protection requires: feature file updated when tests are affected. Use git blame to track when scenarios were last changed. Review feature files in sprint demos.

What is the Cucumber Coach role in a large organisation?

A Cucumber Coach (or BDD Champion) supports multiple teams in adopting BDD correctly. Responsibilities: run Three Amigos workshops, review and improve feature file quality, identify and fix BDD anti-patterns, build shared step libraries for common flows (login, payment), set up CI/CD integration, create internal BDD guidelines and training materials.

How do you test machine learning model outputs with BDD?

Scenario: When I send image of a cat to the classification API, Then the predicted class should be 'cat' with confidence above 0.90. In step defs, call the ML API and check the response. For non-deterministic outputs, use tolerance: Assert.assertTrue(confidence > 0.90). For data drift detection, run BDD scenarios against new model versions in CI.

How do you integrate Cucumber with Jira Xray for test management?

Xray imports .feature files from Jira, creates Test Plan items linked to stories. Export feature files from Xray to your repo. After test run, import Cucumber JSON results via Xray REST API or Maven plugin. Results appear in Jira against the linked stories and test plans. Traceability: from requirement to test to execution result.

What is property-based testing and how does it complement BDD?

Property-based testing (jqwik, QuickTheory) generates hundreds of random inputs to find edge cases that hand-written tests miss. BDD is example-based — you write specific examples. Complement them: BDD for business-critical happy/sad paths, property-based for input validation and algorithmic correctness. Both can be run in the same CI pipeline.

How do you manage a growing feature file library (100+ feature files)?

Organise by domain/feature area in sub-folders. Use descriptive names (UserAuthentication.feature not Login.feature). Tag consistently with a taxonomy (@smoke, @regression, @api, @ui, @<story-id>). Archive obsolete scenarios rather than deleting (comment with reason). Regular grooming sessions to review and remove outdated scenarios. Generate a coverage matrix from tags.

What makes a world-class BDD implementation?

1. Three Amigos genuinely happens before development. 2. Scenarios are written in business language — no technical jargon. 3. Feature files are the source of truth — kept updated. 4. Full CI/CD integration with quality gates. 5. Metrics tracked and reviewed. 6. Flakiness < 2%. 7. Stakeholders read and validate scenarios. 8. Step libraries shared across teams. 9. Onboarding includes BDD training. 10. Automation informs product decisions.

BDD Complete Guide · 5 Levels · 105 Interview Q&As · Gherkin · Cucumber · Hooks · Parallel · API BDD · CI/CD · Screenplay

FAQs

When should a team not use BDD?

When nobody outside the test team reads or writes the scenarios: Gherkin then adds a layer of maintenance without the collaboration benefit, and plain test code is simpler.