Getting started
Install the Symfony bundle, configure intercepted hosts, and run a first in-process browser test.
The bundle requires PHP 8.2 or newer, Symfony 6.4, 7, or 8, and the core Playwright PHP package. Node.js runs the Playwright driver; the default minimum is Node.js 20.
The bundle is currently alpha. Pin it deliberately, review its changelog before upgrades, and keep the browser suite separate from fast tests.
Install the bundle and browsers
composer require --dev playwright-php/playwright-symfony
vendor/bin/playwright-install
vendor/bin/playwright-install chromium
Symfony Flex normally registers the bundle for the test environment. If the project does not use the recipe, add it explicitly:
<?php
return [
Playwright\Symfony\PlaywrightSymfonyBundle::class => ['test' => true],
];
Configure the URL used by visit() and the hosts that should be routed into the kernel:
# config/packages/test/playwright.yaml
playwright:
base_url: 'http://localhost'
intercepted_hosts:
- 'localhost'
- '127.0.0.1'
The base URL host must appear in intercepted_hosts. Requests to any other host leave the process through the normal browser network.
Write the first test
<?php
namespace App\Tests\E2E;
use Playwright\Symfony\Test\PlaywrightTestCase;
use function Playwright\Testing\expect;
final class HomepageTest extends PlaywrightTestCase
{
public function testHomepageIsVisible(): void
{
$page = $this->visit('/');
$this->assertResponseIsSuccessful();
expect($page->getByRole('heading', ['name' => 'Welcome']))->toBeVisible();
}
}
visit() navigates the real page and returns the normal Playwright Page. The Symfony assertion checks the intercepted response. The Playwright assertion checks the rendered browser state.
Run this suite through PHPUnit:
vendor/bin/phpunit tests/E2E
For a visible local run:
PLAYWRIGHT_HEADLESS=false vendor/bin/phpunit tests/E2E
Put E2E tests in a dedicated PHPUnit testsuite or group so ordinary unit tests never launch a browser accidentally.
Next steps
- Choose the right checks: Assertions.
- Review the available options: Configuration.
- Learn the request flow: Kernel and browser lifecycle.
- Set up known application state: Fixtures and mocking.