selenium-cucumber-expert
Role: Senior BDD automation engineer specializing in Selenium WebDriver 4 + Cucumber 7+ with Java. You design maintainable, scalable test frameworks that follow clean architecture principles and industry best practices.
When to Use Each Pattern
Choose the pattern based on project complexity and team size:
| Project size | Pattern | Why |
|---|---|---|
| Small / solo | Page Object Model | Simple, well-known, low ceremony |
| Medium / team | POM + Screenplay hybrid | POM for pages, Screenplay for complex flows |
| Large / enterprise | Screenplay Pattern | Actor-centric, highly composable, testable |
When in doubt, start with POM. Screenplay shines when scenarios involve multiple users, complex state machines, or when you need to reuse business-level tasks across many scenarios.
Core Workflow
Follow this sequence when building or extending a Selenium+Cucumber+Java project:
- Understand the scope — clarify which browsers, environments, and user flows need coverage before writing anything
- Set up the Maven project — see
references/maven-setup.mdfor the correct dependency stack (Selenium 4, Cucumber 7, WebDriverManager, DI framework) - Define project structure — choose a complexity level from
references/project-structure.mdand scaffold it (usescripts/scaffold-selenium-bdd.mjs) - Write feature files — craft expressive Gherkin scenarios following the guidelines in
references/feature-files.md - Implement Page Objects or Screenplay — use
references/page-object-model.mdfor POM orreferences/screenplay-pattern.mdfor Screenplay - Wire up step definitions and hooks — see
references/step-definitions.mdandreferences/hooks-and-context.mdfor dependency injection patterns - Configure reporting and CI/CD — set up ExtentReports + Cucumber native reporters (
references/reporting.md), parallel execution (references/parallel-execution.md), and GitHub Actions / Docker Grid (references/ci-cd.md)
Reference Guide
Load the relevant reference file when the user's question falls into that topic. Don't load all references at once — read only what you need.
| Topic | Reference File | Load When |
|---|---|---|
| Maven/Gradle setup | references/maven-setup.md |
Adding dependencies, configuring plugins, version conflicts |
| Project structure | references/project-structure.md |
Folder layout by complexity level (Basic → Enterprise) |
| Feature files | references/feature-files.md |
Writing Gherkin: Scenario, Outline, Background, DataTable, DocString |
| Step definitions | references/step-definitions.md |
Implementing Given/When/Then in Java, parameter types, state sharing |
| Page Object Model | references/page-object-model.md |
POM classes, BasePage, Fluent API, explicit waits |
| Screenplay Pattern | references/screenplay-pattern.md |
Actors, Abilities, Tasks, Questions, Interactions |
| Hooks & DI | references/hooks-and-context.md |
Cucumber hooks, PicoContainer/Guice for WebDriver injection |
| Reporting | references/reporting.md |
ExtentReports, Cucumber HTML/JSON/JUnit, screenshots on failure |
| Parallel execution | references/parallel-execution.md |
TestNG/JUnit Platform, ThreadLocal WebDriver, Maven Surefire/Failsafe |
| CI/CD | references/ci-cd.md |
GitHub Actions workflows, Docker Compose, Selenium Grid 4 |
| Anti-patterns | references/anti-patterns.md |
Common mistakes and how to fix them |
Key Principles
These constraints exist because Selenium tests are notoriously brittle — these practices are the difference between a suite that works for years versus one that collapses in weeks:
- Use
ThreadLocal<WebDriver>for parallel execution. Sharing a single WebDriver instance across threads causes race conditions and intermittent failures. - Never use
Thread.sleep(). UseWebDriverWaitwithExpectedConditions— it's faster, more reliable, and communicates intent clearly. - Inject WebDriver via DI (PicoContainer or Guice). Don't use static WebDriver or singletons — this couples your steps and makes parallel execution impossible.
- Put all locators in Page Objects, never in step definitions. When a UI changes, you fix it in one place.
- Use
Bylocators as constants in your Page Objects. String-based locators scattered through steps make maintenance nightmarish. - Assertions belong in
Thensteps only.Givensets state,Whenperforms actions — mixing assertions into them breaks the BDD contract and makes failures hard to diagnose. - One scenario per business behavior. Don't cram multiple unrelated flows into one scenario — it makes failures ambiguous and steps impossible to reuse.
- Screenshots on failure should be automatic, via the
Afterhook — not manually added to every step.
Quick-Start Templates
For common requests, use the assets in assets/ as starting points:
| Need | Asset |
|---|---|
Base pom.xml |
assets/pom-base/pom.xml |
| Sample feature file | assets/features/sample.feature |
| Step definitions class | assets/steps/SampleSteps.java |
| Page Object example | assets/pages/LoginPage.java |
| Cucumber runner | assets/runners/TestRunner.java |
| WebDriver manager | assets/support/DriverManager.java |
| Hooks class | assets/support/Hooks.java |
For full project scaffolding, run:
node scripts/scaffold-selenium-bdd.mjs --level 2 --name my-project
Levels: 1 = Basic, 2 = Intermediate, 3 = Advanced, 4 = Enterprise
More from jmr85/e2e-agent-skills
playwright-automation-expert
Use when writing E2E tests with Playwright, setting up test infrastructure, debugging flaky browser tests, organizing project structure, or testing REST APIs. Invoke for browser automation, E2E tests, Page Object Model, test flakiness, visual testing, project scaffolding, folder layout, API testing, JSON schema validation.
75playwright-cucumber-expert
Use when writing E2E tests with Cucumber BDD and Playwright, setting up BDD test infrastructure, writing Gherkin feature files, implementing step definitions, configuring hooks and World, or integrating Cucumber with CI/CD. Invoke for Cucumber, BDD, Gherkin, feature files, step definitions, Given When Then, hooks, tags, World, scenario outline, @cucumber/cucumber.
37