GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - playwright-php/playwright: Playwright PHP library for browser automation: navigation, E2E tests, assertions, screenshots, and so much more!

BranchesTags
Open more actions menu

Latest commit

 

History

171 Commits
171 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
bin
bin
 
 
docs
docs
 
 
src
src
 
 
tests
tests
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.php-cs-fixer.dist.php
.php-cs-fixer.dist.php
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
NOTICE
NOTICE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
phpstan.dist.neon
phpstan.dist.neon
 
 
phpunit.dist.xml
phpunit.dist.xml
 
 

Repository files navigation

Playwright PHP

  PHP Version   CI   Release   License

Playwright PHP

Automate Chromium, Firefox, and WebKit from PHP for browser testing, scraping, screenshots, and other browser-driven workflows.

  • Familiar browser, context, page, and locator model
  • Auto-waiting interactions
  • PHPUnit integration with fluent expect() assertions
  • No separate server to manage: the package starts its bundled Node server

Requirements:

  • PHP 8.2+
  • Node.js 20+ (used by the bundled Playwright server and browsers)

Installation

Add the library to your project:

composer require --dev playwright-php/playwright

Install the Playwright browsers (Chromium, Firefox, WebKit):

# Run after composer install in your application or in this repository
vendor/bin/playwright-install --browsers

# Or install only the browser targets your project uses
vendor/bin/playwright-install chromium

# On fresh machines/CI where you need Playwright's OS dependencies too
vendor/bin/playwright-install --with-deps

# Preview commands without changes
vendor/bin/playwright-install --dry-run --with-deps

For targeted installation, browser cache location, and Chrome or Edge channels, see Browsers, Browser Types, and Channels.

Quick Start

Open a page and print its title:

<?php

require __DIR__.'/vendor/autoload.php';

use Playwright\Playwright;

$context = Playwright::chromium(['headless' => true]);
$page = $context->newPage();
$page->goto('https://example.com');

echo $page->title().PHP_EOL; // Example Domain

$context->close();

Documentation

  • Quick Start Guide
  • Playwright Inspector
  • Contributing: Testing

Usage

Browser

  • Choose a browser: Playwright::chromium(), Playwright::firefox(), or Playwright::webkit().
  • Playwright::safari() is an alias of webkit().
  • Supported launch options: headless (bool), slowMo (ms), args (array of CLI args), and an optional context array with context options.
$context = Playwright::webkit([
    'headless' => false,
    'slowMo'   => 200,
    'args'     => ['--no-sandbox'],
    // 'context' => [ ... context options ... ],
]);

Unknown launch option names throw InvalidArgumentException. For options such as channel and proxy, use PlaywrightConfigBuilder with PlaywrightFactory.

Page

Create pages, navigate, evaluate scripts, and take screenshots:

$page = $context->newPage();
$page->goto('https://example.com');

$html  = $page->content();
$title = $page->title();

$path = $page->screenshot(__DIR__.'/screenshot.png');

Locators and interactions

$button = $page->locator('text=Sign in');
$button->click();

$username = $page->locator('#username');
$username->fill('[email protected]');

$password = $page->locator('#password');
$password->fill('s3cret');
$password->press('Enter');

Storage state and context reuse

$context->storageState(__DIR__.'/state.json');

// Later in another process
$ctx = Playwright::chromium([
  'context' => ['storageState' => __DIR__.'/state.json'],
]);

PHPUnit integration

The package provides a testing trait and fluent expect() assertions to write robust E2E tests.

Requirements: PHPUnit 10.0 or higher is required to use the PlaywrightTestCaseTrait.

Minimal example:

<?php

use PHPUnit\Framework\TestCase;
use Playwright\Testing\PlaywrightTestCaseTrait;

final class HomePageTest extends TestCase
{
    use PlaywrightTestCaseTrait;

    protected function setUp(): void
    {
        parent::setUp();
        $this->setUpPlaywright();
    }

    protected function tearDown(): void
    {
        $this->tearDownPlaywright();
        parent::tearDown();
    }

    public function test_title_is_correct(): void
    {
        $this->page->goto('https://example.com');

        $this->expect($this->page)->toHaveTitle('Example Domain');
    }
}

Notes:

  • The trait provides $this->playwright, $this->browser, $this->context, and $this->page properties.
  • Call setUpPlaywright() in setUp() and tearDownPlaywright() in tearDown() for proper lifecycle management.
  • Use $this->expect($locator) or $this->expect($page) for fluent assertions with auto-waiting.
  • If you prefer full control, you can skip the trait and use the static Playwright facade directly.

GitHub Actions

Example workflow snippet:

jobs:
  tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.2'

      - uses: actions/setup-node@v4
        with:
          node-version: '20'

      - run: composer install --no-interaction --prefer-dist

      # Install browsers for Playwright PHP
      - run: vendor/bin/playwright-install --with-deps

      - run: vendor/bin/phpunit --colors=always

Tips:

  • Cache Node and Composer if you need faster builds.
  • You can also cache Playwright browsers under ~/.cache/ms-playwright.

Contributing

Include tests for behavior changes and update documentation or examples when their public behavior changes. Set up the repository with:

composer install                                # installs PHP deps and the bundled Playwright server
bin/playwright-install --with-deps              # downloads browsers + optional system deps
make ci                                         # runs code style, static analysis, and tests

See docs/contributing/testing.md for more details on the local workflow.

License

This package is released by the Playwright PHP project under the MIT License. See the LICENSE file for details.

About

Playwright PHP library for browser automation: navigation, E2E tests, assertions, screenshots, and so much more!

playwright-php.dev/

Topics

browserbrowser-automationcss-selectorsjson-rpclocatorsphpphp-browserphp-jsphpunitplaywrightscrapingscreenshottest

Resources

Readme
MIT license

Code of conduct

Code of conduct

Security policy

Security policy
Activity
Custom properties

Stars

257 stars

Watchers

4 watching

Forks

26 forks
Report repository

Releases

Sponsor this project

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.