Device presets
Preset viewports for flagship phones.
Playwright PHP - Browser Automation
Full Playwright API, native PHP DX — just real browsers and first-class assertions.
<?php
use Playwright\Playwright;
$browser = Playwright::chromium();
$page = $browser->newPage();
$page->goto('https://playwright-php.dev');
echo $page->title();
echo $page->locator('h1')->textContent();
$page->screenshot('example.png');
$browser->close();
<?php
$browser = Playwright::chromium([
'headless' => true,
'viewport' => [
'width' => 1920,
'height' => 1080
],
'screen' => [
'width' => 3840,
'height' => 2160
]
]);
$page = $browser->newPage();
$page->goto('https://www.whatsmybrowser.org');
echo $page->title();
Preset viewports for flagship phones.
Headless runs emit traces and HARs.
<?php
$button = $page->getByRole('button', ['name' => 'Add to cart']);
$input = $page->getByLabel('Email');
$products = $page->locator('.product');
$firstProduct = $products->first();
$recentProducts = $products->filter(['hasText' => 'new']);
$price = $products->locator('.price');
Auto-wait spans selectors, navigation, and assertions.
Open tabs, switch contexts, and drive back/forward entirely in PHP.
<?php
// Mouse
$page->locator('#search-input')->hover();
$page->mouse->move(220, 410);
// Keyboard
$page->locator('#search-input')->focus();
$page->keyboard->type('Hello World', ['delay' => 100]);
$page->keyboard->press('Control+A');
// Click, Type, Tap
$page->click('button#add-to-cart');
Upload fixtures, streams, buffers like users.
Send chords, modifiers, full shortcuts.
<?php
// Assert on page
expect($page)->toHaveTitle('Products - Example Store');
expect($page)->not()->toHaveURL('/error');
// Assert on locators
expect($page->locator('.product-title'))->toBeVisible();
expect($page->locator('button'))->toHaveAttribute('type', 'submit');
expect($page->locator('.grid'))->toHaveCss('display', 'grid');
Drop in assertions into your tests.
Block or mock assets and API calls.
<?php
$context = Playwright::chromium();
$page = $context->newPage();
$context->startTracing($page);
$page->goto('https://example.com');
$page->click('button');
$context->stopTracing($page, 'trace.zip');
// trace.zip contains DOM snapshots, interactions, and resources loaded
Skip timers and intervals instantly.
Record MP4 runs for handoffs, CI.
# 1. Install the package
composer require playwright-php/playwright
# 2. Download browsers
vendor/bin/playwright install
Report bugs, suggest features, or submit pull requests to improve the library.
Support ongoing development and maintenance through GitHub Sponsors.
Share your ideas, report issues, or request features to help shape the future of the project.
Write tutorials, share on social media, or tell your team about Playwright PHP.