Warning
This package is in active development phase.
A Behat extension that integrates PlaywrightPHP for modern browser automation testing.
composer require playwrightphp/behat-extension --devAdd 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\PlaywrightContextFeature: 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"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();
}
}| 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) |
Given I am on ":url"When I go to ":url"
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"
When I wait for ":selector"When I wait :seconds secondsWhen I wait for the page to load
Then I should see ":text"Then ":selector" should be visibleThen the current URL should contain ":fragment"
And many more! Check the PlaywrightContext class for all available steps.
This package is released by the Playwright PHP project under the MIT License. See the LICENSE file for details.