Search by

playwright-php / playwright-behat

Maintainers

Package info

github.com/playwright-php/playwright-behat

pkg:composer/playwright-php/playwright-behat

Transparency log

Fund package maintenance!

smnandre

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main / 0.x-dev 2026-09-02 17:18 UTC

This package is auto-updated.

Last update: 2026-09-02 17:19:37 UTC


README

  PHP Version   CI   Release   License

PlaywrightPHP - Behat Extension

Warning

This package is in active development phase.

A Behat extension that integrates PlaywrightPHP for modern browser automation testing.

Installation

composer require playwrightphp/behat-extension --dev

Configuration

Add the extension to your behat.yml:

default:
  extensions:
    Playwright\Behat\ServiceContainer\PlaywrightExtension:
      headless: false
      browser: chromium
      screenshot_dir: 'var/screenshots'
      timeout: 30000
      base_url: 'http://localhost:8000'
      viewport:
        width: 1280
        height: 720
      
  suites:
    web:
      paths: ['features']
      contexts:
        - Playwright\Behat\Context\PlaywrightContext

Usage

Basic Steps

Feature: User Authentication
  Scenario: Login with valid credentials
    Given I am on "/login"
    When I fill "#email" with "user@test.com"
    And I fill "#password" with "password123"
    And I click on "#login-button"
    Then I should see "Welcome"

Custom Context

Extend RawPlaywrightContext for custom logic:

use Playwright\Behat\Context\RawPlaywrightContext;
use Behat\Step\When;

class MyCustomContext extends RawPlaywrightContext
{
    #[When('I login as admin')]
    public function loginAsAdmin(): void
    {
        $this->page->goto('/admin/login');
        $this->page->locator('#username')->fill('admin');
        $this->page->locator('#password')->fill('secret');
        $this->page->locator('[type="submit"]')->click();
    }
}

Configuration Options

Option Type Default Description
headless bool true Run browser in headless mode
browser string chromium Browser type (chromium, firefox, webkit)
screenshot_dir string %paths.base%/var/screenshots Screenshot directory
timeout int 30000 Default timeout in milliseconds
base_url string null Base URL for relative paths
viewport.width int 1280 Browser viewport width
viewport.height int 720 Browser viewport height
auto_screenshot_on_failure bool true Auto screenshot on failure
browser_options array [] Additional browser launch options
slow_mo.delay int 0 Delay between actions (ms)

Available Steps

Navigation

  • Given I am on ":url"
  • When I go to ":url"

Interactions

  • When I click on ":selector"
  • When I fill ":selector" with ":value"
  • When I select ":value" from ":selector"
  • When I check ":selector"
  • When I press ":button"

Waits

  • When I wait for ":selector"
  • When I wait :seconds seconds
  • When I wait for the page to load

Assertions

  • Then I should see ":text"
  • Then ":selector" should be visible
  • Then the current URL should contain ":fragment"

And many more! Check the PlaywrightContext class for all available steps.

License

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