Examples

Runnable scripts and workflow examples you can use to understand Playwright PHP by doing.

Start here

Four small runnable scripts cover the basic loop: open a page, move through it, assert the result, and capture evidence.

Before you run an example

Examples are complete, practical pages. Most are PHP scripts you can copy, run, and adapt. A few are workflow examples for companion packages or tooling, where the useful artifact is a setup pattern rather than one standalone script.

Use examples when you want to learn by running code. Use recipes when you need the shortest answer to one task. Use the API reference when you need exact method names and signatures.

Start with Visit a page, then move to Navigate and click, Assert with expect, and Take a screenshot. After that, pick a group by what you want to prove: browser setup, captured output, assertions, network work, or debugging.

Each card still tells you which kind it is:

  • Runnable script: has a .php source file shown on the page.
  • Workflow example: explains a repeatable setup, prompt, or package workflow.

Prerequisites

bash
composer require --dev playwright-php/playwright

# Install the browser used by the examples
vendor/bin/playwright-install chromium

On a fresh machine or in CI, install browsers plus system dependencies:

bash
vendor/bin/playwright-install --with-deps chromium

Requirements: PHP 8.2 or newer, and Node.js 20 or newer. The Node server that Playwright uses starts automatically; there is nothing to run by hand.

Running a script example

Runnable examples are plain PHP files. Run them directly:

bash
php content/examples/visit.php

Do not run every file in content/examples blindly. Some examples open the inspector, start a server, or require environment variables. Pick the script for the page you are reading.

Workflow examples do not have a source block. Follow the commands or checklist on the page instead. The sidebar stays focused on reader lanes here, then on the current group inside an example.

First scripts and browser setup

After the first four scripts, vary how the browser starts and what environment the page sees.

Capture output

Capture the browser output when the result needs to be stored, reviewed, or shared.

Assertions and interactions

Move beyond page visits by driving richer interactions.

Network and API work

Call HTTP endpoints, block unnecessary resources, and stub application responses from the browser side.

Debugging & workflows

Use console output, the inspector, long-lived browser servers, companion packages, and assistant-safe workflows.