Playwright BDD: Combining Cucumber with Page Objects

profile
Mike Sell
crashnaut.com

Playwright BDD: Combining Cucumber with Page Objects

The Problem with Functional BDD Implementations link

I've seen many BDD implementations that start well but become unmaintainable over time. The most common issue? Using functional programming patterns with utility functions instead of proper Page Objects.

Here's what typically happens:

The Solution: BDD + POM link

The answer is simple: combine the readability of BDD/Gherkin with the maintainability of the Page Object Model.

Feature Files (Gherkin) link

Write scenarios in business language:

Page Objects (Maintainable UI Logic) link

Encapsulate UI interactions in page classes:

Step Definitions (The Glue) link

Connect Gherkin to Page Objects:

Key Architecture Decisions link

Domain-Driven Page Objects link

Don't use a generic pages/ folder. Organize by feature domains:

This matches your application structure and makes it easy to find what you need.

Combined Factory + Navigation link

Instead of separate navigation and factory classes, use a combined approach:

Cleaner API, less boilerplate.

No Assertions in Page Objects link

Keep page objects pure:

Docker for Consistency link

Two modes of testing:

Local Mode (PR Testing) link

Remote Mode (Environment Testing) link

CI/CD Integration link

Three GitHub Actions workflows:

  1. PR Workflow - Every pull request
  2. Dev Workflow - After deployments
  3. Smoke Workflow - Every 6 hours against all environments

All running in Docker for consistency.

Benefits of This Approach link

For Product/BA link

For QA/SDET link

For Developers link

The Boilerplate link

I've created a complete boilerplate with:

Get it here: GitHub - playwright-bdd-boilerplate

Getting Started link

That's it. Five minutes from clone to running tests.

When to Use BDD vs Plain POM link

Use BDD when:

Use plain POM when:

Lessons Learned link

1. Don't Use Functional Utilities link

I've refactored too many codebases with messy utility functions. Page Objects are worth the upfront structure.

2. Keep Step Definitions Thin link

All logic belongs in page objects. Step definitions should just call page object methods and assert.

3. Tag Everything link

Use tags (@smoke, @regression) to run different test suites. Not every test needs to run on every commit.

4. Docker is Non-Negotiable link

The "works on my machine" problem is real. Docker ensures consistency.

Resources link

Wrapping Up link

BDD doesn't have to mean unmaintainable test code. By combining Gherkin with proper Page Objects, you get the best of both worlds: readable tests that stakeholders understand, and maintainable code that scales with your application.

More posts coming on Playwright patterns, Docker testing strategies, and CI/CD optimization. Follow me for updates.

Feel free to update this blog post on GitHub, thanks in advance!

Share this post

Support me

I appreciate it if you would support me if you have enjoyed this post and found it useful, thank you in advance.

Buy Me a Coffee at ko-fi.com