This is a DDEV addon that provides a Playwright testing environment for your DDEV projects.
ddev add-on get codingsasi/ddev-playwright
ddev restart # This will build Playwright browsers into the Docker image
This addon builds Playwright browsers directly into the DDEV web container Docker image. This means:
ddev restart
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.
After installation, browsers are already installed. You can verify the installation:
# Verify Playwright and browser installation (optional)
ddev install-playwright
You can run Playwright commands directly using the ddev playwright
command:
# Run Playwright tests
ddev playwright test
# Show Playwright help
ddev playwright --help
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...
});
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.ts
Runs before all tests execute. The included setup file demonstrates:
global-teardown.ts
Runs 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 “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.