Your first script

Open a stable page, read its heading, and verify the result from a plain PHP file.

A Playwright PHP script is a normal PHP file. No test runner or config is required.

Create the script

Save this as first-script.php:

php
<?php

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

use Playwright\Playwright;

use function Playwright\Testing\expect;

$context = Playwright::chromium();
$page = $context->newPage();

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

expect($page)->toHaveTitle('Example Domain');
expect($page->getByRole('heading'))->toHaveText('Example Domain');

echo "OK\n";

$context->close();

Run it

bash
php first-script.php

Expected result:

text
OK

The script launches Chromium, opens a stable public page, waits for the title and heading, then exits.

What happened

  • Playwright::chromium() starts a real browser context.
  • newPage() opens a tab.
  • getByRole() finds the heading by how users and assistive technology see it.
  • expect() retries until the page title matches or times out.

Watch the browser

If you want to see the browser while developing:

php
$page = Playwright::chromium(['headless' => false])->newPage();

Keep scripts headless by default for CI.

If it fails

  • If PHP cannot find vendor/autoload.php, run the script from the project root or install dependencies with Composer.
  • If Chromium cannot start, run vendor/bin/playwright-install chromium and retry.
  • If the assertion times out, keep https://example.com for the first run. Replace it with your app only after the baseline script passes.

Next

Continue with Write your first test.

If you need more context first, learn how a browser test is structured or how to choose a locator.