PlaywrightClient
Playwright\Symfony\BrowserKit\PlaywrightClient
Public BrowserKit client for real browser testing with Playwright (no kernel routing).
This is the standalone, public-facing client for using Playwright with Symfony's BrowserKit API.
It performs real browser navigation via actual HTTP requests - there is NO request interception
and NO routing through Symfony's HttpKernel.
Primary role in architecture:
- Public API for users who want BrowserKit compatibility with real Playwright browsers
- Can be autowired from the container (registered by PlaywrightBundle)
- Works with any website (internal or external) via real HTTP
- Provides DomCrawler snapshots of the live DOM after each action
Key differences from PlaywrightKernelClient:
- Uses REAL HTTP requests (not in-process kernel routing)
- Can test external websites and APIs
- NO access to Symfony internals (no request/response inspection, no profiler)
- Cookies synced between Playwright context and BrowserKit's CookieJar
How it works:
1. User calls request('GET', 'https://example.com')
2. Playwright navigates via page->goto() → real HTTP request
3. Page loads with full browser behavior (JS, CSS, AJAX)
4. Client builds DomCrawler from page->content()
5. Returns Crawler for BrowserKit-compatible assertions
Features:
- Real browser semantics: click(), submit() use Playwright actions (not synthetic HTTP)
- Popup support: opt-in via setFollowPopups(true), switches to new tabs when links open them
- Form handling: creates synthetic forms in-page to preserve browser events
- Cookie sync: keeps BrowserKit CookieJar in sync with Playwright context
- Server params: maps HTTP_* headers and PHP_AUTH_* credentials to Playwright
When to use:
- Testing external websites or APIs
- Need real HTTP networking behavior
- Want BrowserKit API with real browser (alternative to Symfony Panther)
- Testing JavaScript-heavy applications
When NOT to use:
- Testing your Symfony app with access to internals → use PlaywrightTestCase instead
- Need to inspect Symfony request/response → use PlaywrightKernelClient via PlaywrightTestCase
Usage:
```php
// Via dependency injection
$client = $container->get(PlaywrightClient::class);
// Or manual instantiation
$context = Playwright::chromium();
$client = PlaywrightClient::fromContext($context);
// BrowserKit API
$crawler = $client->request('GET', 'https://example.com');
$link = $crawler->selectLink('Documentation')->link();
$crawler = $client->click($link);
```
Methods
__construct()
function __construct( BrowserContextInterface $context, PageInterface $page, array $server = [], ?History $history = null, ?CookieJar $cookieJar = null, )
fromContext()
selffunction fromContext( BrowserContextInterface $context, array $server = [], ?History $history = null, ?CookieJar $cookieJar = null, ): self
getPage()
PageInterfacefunction getPage(): PageInterface
setFollowPopups()
voidEnables or disables following popups opened by click() and submit(). When enabled, an action that opens a new tab makes the client switch to it (Panther-like). Every action then waits for a potential popup before returning, which adds the popup timeout to actions that do not open one: enable it only for interactions expected to open a new tab.
function setFollowPopups(bool $followPopups): void
getLastResponse()
?BrowserKitResponsefunction getLastResponse(): ?BrowserKitResponse
click()
Crawlerfunction click(Link $link, array $serverParameters = []): Crawler
submit()
Crawlerfunction submit(Form $form, array $values = [], array $serverParameters = []): Crawler