This is a DDEV addon that provides a Playwright testing environment for your DDEV projects.
Add the addon (you will be prompted for Playwright version):
ddev add-on get codingsasi/ddev-playwright
Restart to build the web container with Playwright support:
ddev restart
Init Playwright and install browsers (uses the version from your config):
ddev install-playwright
Run tests — ddev playwright is the Playwright CLI:
ddev playwright test
The addon depends on ddev-nvm; the Playwright project folder gets a default .nvmrc set to Node 22 (Node 20+ is required).
This addon builds Playwright browsers into the DDEV web container image and uses a persistent browser path (/opt/playwright-browsers). After ddev install-playwright, browsers are installed there and persist across restarts.
ddev reinstall-browsersBy default, Playwright tests are installed in the tests/playwright directory. You can customize this location by setting the PLAYWRIGHT_TEST_DIR environment variable in your .ddev/config.yaml:
web_environment:
- PLAYWRIGHT_TEST_DIR=test # Use "test" instead of "tests"
After changing this setting, run:
ddev restart
Note: If you change this after initial installation, you’ll need to manually move your existing Playwright directory to the new location.
During ddev add-on get you will be prompted to enter a version:
Playwright version configuration
See releases: https://github.com/microsoft/playwright/releases
Enter Playwright version [latest]:
Press Enter to use the latest release, or type a specific version (e.g. 1.49.0). The choice is written directly into your project’s .ddev/config.yaml — commit this file so the whole team uses the same version.
To change the version later, run ddev add-on get again (you will be prompted only if the version is not yet set) or edit PLAYWRIGHT_VERSION in .ddev/config.yaml under web_environment and run ddev restart:
ddev playwright is the Playwright CLI (pass any Playwright CLI args):
ddev playwright test
ddev playwright --help
ddev playwright codegen
ddev playwright show-report --host=0.0.0.0 # then open http://<project>.ddev.site:9323
Commands:
| Command | Description |
|---|---|
ddev install-playwright |
Init Playwright project (if needed), install browsers, set up .installed to indicate browsers are installed |
ddev reinstall-browsers |
Reinstall browser binaries even if already installed |
ddev playwright ... |
Run the Playwright CLI (e.g. test, codegen, show-report) |
Your tests can access 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 || 'https://your.ddev.site');
// Rest of your test...
});
# From project root
cd tests/playwright # Go into playwright folder (or "test/playwright" if you customized PLAYWRIGHT_TEST_DIR)
nvm use 22
npm ci
npx playwright install # Works best on Windows, Mac and Ubuntu (and possibly other Debian based distros). I had trouble with Fedora/Manjaro but not impossible.
npx playwright test --ui
This will open up the playwright UI which you can use to run tests manually. See screenshot below.

You should also update playwright.config.ts with your ddev base url: const baseURL = process.env.DDEV_PRIMARY_URL || 'https://your.ddev.site';
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.
global-setup.tsRuns before all tests execute. The included setup file demonstrates:
global-teardown.tsRuns after all tests complete. The included teardown file demonstrates:
Both files automatically detect the execution environment:
process.env.CI): Uses platform CLI commands for cloud hostingprocess.env.IS_DDEV_PROJECT): Runs drush commands directlyddev to execute in the containerEdit 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.
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.
Feel free to submit issues or pull requests with improvements.
Contributed and maintained by [Abhai Sasidharan/codingsasi]
This is a very lightweight playwright ddev addon, if you want a more advanced playwright integration into ddev, use Lullabot’s playwright ddev addon or Julien Loizelet’s ddev addon. 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.
As of DDEV v1.25.0, nvm is no longer included by default. In most cases this will be required (Drupal themes, progressively decoupled apps, full decoupled apps etc). So for this add-on, I’ve added ddev-nvm as a dependency and it is required for this add-on.