Download the PHP package skylerkatz/phpunit-plugin-browser without Composer
On this page you can find all versions of the php package skylerkatz/phpunit-plugin-browser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download skylerkatz/phpunit-plugin-browser
More information about skylerkatz/phpunit-plugin-browser
Files in skylerkatz/phpunit-plugin-browser
Package phpunit-plugin-browser
Short Description PHPUnit extension for browser testing with Playwright
License MIT
Informations about the package phpunit-plugin-browser
PHPUnit Browser Plugin
A PHPUnit extension for browser testing powered by Playwright.
Attribution: This package is a port of pestphp/pest-plugin-browser by Nuno Maduro and the Pest team. Full credit goes to the original authors for the API design and Playwright integration. This package adapts that work for use with PHPUnit directly.
Requirements
- PHP 8.3+
ext-sockets- PHPUnit 11+
- Node.js (required for Playwright)
Installation
Install via Composer:
Install Playwright browsers:
PHPUnit Configuration
Register the extension in your phpunit.xml:
You can pass optional parameters directly in the bootstrap:
Writing Tests
Extend BrowserTestCase and use $this->visit() to open a page:
Basic Example
Form Interactions
Dropdowns, Checkboxes, and Radio Buttons
Device Emulation
Available devices include DESKTOP, MOBILE, MACBOOK_16, IPHONE_15_PRO, IPAD_PRO, PIXEL_8, GALAXY_S24_ULTRA, SURFACE_PRO_9, and more.
Dark Mode
Screenshot Assertions
JavaScript Execution
Multiple URLs
iFrames
Configuration
Environment Variables
| Variable | Description |
|---|---|
BROWSER_HEADED |
Show the browser window (true/false) |
BROWSER_DEBUG |
Enable debug mode on failures |
BROWSER_DIFF |
Show diffs on screenshot failures |
BROWSER_DARK |
Use dark color scheme |
BROWSER_LIGHT |
Use light color scheme |
BROWSER_TYPE |
Browser: chrome, firefox, or safari |
BROWSER_TIMEOUT |
Assertion timeout in milliseconds |
BROWSER_HOST |
Playwright server host |
Runtime Configuration
Configure globally in your test's setUp method:
Available Assertions
Element Assertions
| Method | Description |
|---|---|
assertTitle($title) |
Assert page title matches exactly |
assertTitleContains($text) |
Assert page title contains text |
assertSee($text) |
Assert text is visible on page |
assertDontSee($text) |
Assert text is not visible |
assertSeeIn($selector, $text) |
Assert text is visible within element |
assertDontSeeIn($selector, $text) |
Assert text is not visible within element |
assertPresent($selector) |
Assert element exists in DOM |
assertMissing($selector) |
Assert element does not exist in DOM |
assertVisible($selector) |
Assert element is visible |
assertEnabled($selector) |
Assert element is enabled |
assertDisabled($selector) |
Assert element is disabled |
assertChecked($selector) |
Assert checkbox is checked |
assertSelected($selector, $value) |
Assert select has value |
assertValue($selector, $value) |
Assert input has value |
assertAttribute($selector, $attr, $value) |
Assert element attribute value |
assertAriaAttribute($selector, $attr, $value) |
Assert ARIA attribute value |
assertDataAttribute($selector, $attr, $value) |
Assert data attribute value |
assertSourceHas($code) |
Assert page source contains string |
assertSourceMissing($code) |
Assert page source does not contain string |
assertSeeLink($url) |
Assert link is visible |
assertDontSeeLink($url) |
Assert link is not visible |
URL Assertions
| Method | Description |
|---|---|
assertUrlIs($url) |
Assert full URL matches (supports * wildcards) |
assertUrlContains($text) |
Assert URL contains text |
assertQueryStringHas($key, $value) |
Assert query string parameter |
Screenshot Assertions
| Method | Description |
|---|---|
assertScreenshotMatches($fullPage) |
Visual regression test against baseline |
Available Interactions
| Method | Description |
|---|---|
click($selector) |
Click an element |
press($text) |
Press a button by text |
type($selector, $value) |
Type into an input |
typeSlowly($selector, $value) |
Type character by character |
fill($selector, $value) |
Fill an input (clears first) |
clear($selector) |
Clear an input |
append($selector, $value) |
Append text to an input |
select($selector, $value) |
Select a dropdown option |
check($selector) |
Check a checkbox |
uncheck($selector) |
Uncheck a checkbox |
radio($selector, $value) |
Select a radio button |
hover($selector) |
Hover over an element |
rightClick($selector) |
Right-click an element |
drag($from, $to) |
Drag and drop |
keys($selector, $keys) |
Send keyboard input |
attach($selector, $path) |
Upload a file |
script($js) |
Execute JavaScript |
Migrating from Pest
This package includes a CLI tool to convert Pest test files to PHPUnit. It handles structural transformations (test()/it() to class methods, expect() chains to PHPUnit assertions, beforeEach/afterEach to setUp/tearDown, etc.) and converts visit() calls to $this->visit().
What gets converted
| Pest | PHPUnit |
|---|---|
test('name', function () { ... }) |
public function test_name(): void { ... } |
it('does something', function () { ... }) |
public function test_it_does_something(): void { ... } |
describe('group', ...) |
Method name prefix (e.g. test_group_name) |
beforeEach(function () { ... }) |
setUp() with parent::setUp() |
afterEach(function () { ... }) |
tearDown() with parent::tearDown() |
uses(RefreshDatabase::class) |
use RefreshDatabase trait |
visit('/') |
$this->visit('/') |
expect($val)->toBe('foo') |
$this->assertSame('foo', $val) |
expect($val)->not->toBeNull() |
$this->assertNotNull($val) |
->skip() |
$this->markTestSkipped() |
->todo() |
$this->markTestIncomplete() |
License
MIT
All versions of phpunit-plugin-browser with dependencies
ext-sockets Version *
amphp/amp Version ^3.1.1
amphp/http-server Version ^3.4.4
amphp/websocket-client Version ^2.0.2
nikic/php-parser Version ^5.0
nunomaduro/collision Version ^8.9
phpunit/phpunit Version ^11.0
symfony/process Version ^7.4.5|^8.0.5