Raised: $0
0% of monthly goal Help us cross the finish line!
Goal: $12,000
Raised: $0 Goal: $12,000
0% of monthly goal Help us cross the finish line!
Sponsor DDEV

ddev-playwright

tests project is maintained ddev-get registry release

This is a DDEV addon that provides a Playwright testing environment for your DDEV projects.

Installation

ddev add-on get codingsasi/ddev-playwright
ddev restart  # This will build Playwright browsers into the Docker image

How It Works

This addon builds Playwright browsers directly into the DDEV web container Docker image. This means:

The first ddev restart after installation will take longer (5-10 minutes) as it builds the browsers into the Docker image. Subsequent restarts will be fast.

Configuration

After installation, browsers are already installed. You can verify the installation:

# Verify Playwright and browser installation (optional)
ddev install-playwright

Usage

You can run Playwright commands directly using the ddev playwright command:

# Run Playwright tests
ddev playwright test

# Show Playwright help
ddev playwright --help

Accessing the Web Application from Tests

Your tests can access the web application using the hostname web or the DDEV_PRIMARY_URL environment variable:

// Example test
import { test, expect } from '@playwright/test';

test('basic test', async ({ page }) => {
  // Using the DDEV_PRIMARY_URL environment variable
  await page.goto(process.env.DDEV_PRIMARY_URL || 'http://web');

  // Rest of your test...
});

Global Setup and Teardown

I’ve included config to have playwright’s global setup and teardown hooks. This allows you to run code once before all tests begin and once after all tests complete. This is useful for:

These hooks run independently of individual test files and are executed in a separate Node.js process.

Configuration Files

global-setup.ts

Runs before all tests execute. The included setup file demonstrates:

global-teardown.ts

Runs after all tests complete. The included teardown file demonstrates:

Environment Detection

Both files automatically detect the execution environment:

Customization

Edit these files to match your project’s needs:

// Example: Custom setup for your application
execSync('drush user:create testuser --password=testpass', { stdio: 'inherit' });
execSync('drush config:set system.site page.front /custom-page', { stdio: 'inherit' });

The global hooks are automatically configured in playwright.config.ts and will run whenever you execute ddev playwright test.

Customizing

You can customize the Playwright configuration by editing the playwright.config.ts file in your project. TypeScript is enforced by initializing playwright with ts when add-on is installed because it brings order to lawless world of JavaScript.

Contributing

Feel free to submit issues or pull requests with improvements.

Contributed and maintained by [Abhai Sasidharan/codingsasi]

Notes

This is a very lightweight playwright ddev addon, if you want a more advanced playwright integration into ddev, use “https://github.com/Lullabot/ddev-playwright” or “https://github.com/julienloizelet/ddev-playwright”. They have a VNC running inside ddev that is capable of –ui. Using my add-on, if you want the –ui to work, you’ll have to run it outside of ddev which is quite easy. See the global-setup.ts and global-teardown.ts files. See more about UI mode here: https://playwright.dev/docs/test-ui-mode.