- PHP: 8.3 or higher.
- Node.js: 20 or higher.
- Composer: Latest version recommended.
Run the following command to add the bundle to your project's development dependencies:
composer require --dev playwright-php/playwright-symfonyAfter installing the bundle via Composer, you must initialize the Playwright environment. The bundle leverages the core
playwright-php installation scripts.
This command sets up the necessary Node.js bridge and internal dependencies:
vendor/bin/playwright-installDownload the required browser binaries (Chromium, Firefox, WebKit). You have two options depending on your environment:
For Local Development:
vendor/bin/playwright-install --browsersFor CI or Fresh Servers (Includes OS Dependencies):
vendor/bin/playwright-install --with-depsThe bundle provides a PlaywrightTestCase class that integrates the browser lifecycle with the Symfony Kernel.
// tests/Controller/HomepageTest.php
namespace App\Tests\Controller;
use Playwright\Symfony\Test\PlaywrightTestCase;
class HomepageTest extends PlaywrightTestCase
{
public function testHomepageIsAccessible(): void
{
// Visit your app (handled in-process via Kernel interception)
$this->visit('/');
// Assert using the built-in helpers
$this->assertResponseIsSuccessful();
$this->assertPageContains('Welcome to Symfony');
// Interact with the real browser using the Playwright Page API
$this->page->locator('a.btn-primary')->click();
$this->assertStringContainsString('/dashboard', $this->page->url());
}
}By default, browser tests are skipped to ensure your standard test suite remains fast. Use the PLAYWRIGHT_E2E
environment variable to enable them.
PLAYWRIGHT_E2E=1 vendor/bin/phpunitTo see what is happening inside the browser during a test run, disable headless mode:
PLAYWRIGHT_E2E=1 PLAYWRIGHT_HEADLESS=false vendor/bin/phpunitTo use a specific browser engine (default is chromium):
PLAYWRIGHT_E2E=1 PLAYWRIGHT_BROWSER=firefox vendor/bin/phpunit