Skip to main content
@wordpress/e2e-test-utils-playwright provides end-to-end test utilities for WordPress using Playwright. It offers fixtures and helpers for testing WordPress admin, the block editor, and WordPress functionality.
This package is under active development. The v0.x version can introduce breaking changes without detailed migration guides. Use a lock file to prevent unexpected breakages.

Installation

Install the package as a dev dependency:
Requirements:
  • Node.js: >= 18.12.0
  • npm: >= 8.19.2
  • WordPress: >= 5.6.0 or Gutenberg: >= 9.2.0

Quick Start

1

Install dependencies

2

Create a test file

tests/example.spec.js
3

Run tests

Core API

test

Extended Playwright test module with WordPress-specific fixtures.
Available fixtures:
  • admin - Admin utilities for WordPress admin interface
  • editor - Block editor utilities
  • pageUtils - Generic page interaction utilities
  • requestUtils - REST API utilities
  • page - Standard Playwright page object

expect

Playwright/Jest’s expect function for assertions.

Fixtures

Admin

Utilities for WordPress admin interface.

visitAdminPage(path)

Navigate to an admin page:

createNewPost()

Create a new post:

createNewPage()

Create a new page:

Editor

Utilities for the WordPress block editor.

insertBlock()

Insert a block:

publishPost()

Publish the current post:

saveDraft()

Save post as draft:

canvas

Access the editor canvas (iframe):

PageUtils

Generic utilities for page interactions.

pressKeys(keys)

Press keyboard shortcuts:
Available modifiers:
  • primary - Ctrl (Windows/Linux), Cmd (Mac)
  • shift
  • alt
  • ctrl

RequestUtils

Utilities for WordPress REST API interactions.
1

Set up RequestUtils

2

Use in tests

createPost(data)

Create a post via REST API:

deleteAllPosts()

Delete all posts:

activatePlugin(slug)

Activate a plugin:

deactivatePlugin(slug)

Deactivate a plugin:

Common Test Patterns

Testing Block Insertion

Testing Admin Pages

Testing with API Setup

Using Custom Editor Setup

Accessing Canvas Elements

The editor uses an iframe, so you must use editor.canvas to access elements inside:

Configuration

Playwright Config

Create a playwright.config.js file:
playwright.config.js

Test Environment Setup

Set up WordPress environment variables:
playwright.config.js

Failed Test Artifacts

When tests fail, artifacts are saved to help with debugging.

Default Location

Artifacts are stored in the artifacts/ directory by default.

Custom Location

Set a custom artifacts directory:

Artifact Types

  • Screenshots - captured when tests fail
  • Videos - recorded test execution
  • Traces - detailed execution traces

Viewing Artifacts

Advanced Usage

Custom Fixtures

Extend the test fixtures:

Multiple WordPress Instances

Test against different WordPress versions:
playwright.config.js

Performance Testing

Measure page performance:

Running Tests

Basic Commands

With wp-scripts

If using @wordpress/scripts:
package.json
Terminal

Best Practices

Troubleshooting

Issue: Can’t find blocks or editor elementsSolution: Use editor.canvas to access iframe content:
Issue: Tests pass/fail intermittentlySolutions:
  1. Use toBeVisible() instead of checking existence
  2. Increase timeout for slow operations
  3. Wait for network idle before assertions
Issue: Can’t access admin pagesSolution: Verify credentials in RequestUtils setup:
Issue: Tests timeout waiting for elementsSolution: Increase timeout in config:
playwright.config.js

Examples Repository

Find more examples in the Gutenberg repository.

Package Information

  • Version: 1.40.0
  • Node.js: >= 18.12.0
  • npm: >= 8.19.2
  • License: GPL-2.0-or-later
  • Peer Dependencies:
    • @playwright/test >= 1
    • @types/node ^20.17.10