PHPackages                             daycry/phpunit-extension-selenium - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. daycry/phpunit-extension-selenium

ActiveLibrary[Testing &amp; Quality](/categories/testing)

daycry/phpunit-extension-selenium
=================================

A library that allows you to easily use the PHP-Selenium library in your PHPUnit tests.

v1.0.2(4mo ago)0118MITPHPPHP ^8.2CI passing

Since Nov 3Pushed 1mo agoCompare

[ Source](https://github.com/daycry/phpunit-extension-selenium)[ Packagist](https://packagist.org/packages/daycry/phpunit-extension-selenium)[ Docs](https://github.com/daycry/phpunit-extension-selenium)[ RSS](/packages/daycry-phpunit-extension-selenium/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (7)Versions (4)Used By (0)

PHPUnit Selenium Extension
==========================

[](#phpunit-selenium-extension)

> Typed, chainable Selenium WebDriver API for PHPUnit. Opt in per test through the `#[UseSelenium]` attribute; sessions are lazy, isolated per test, and support Chrome, Firefox, Edge and Safari out of the box.

### Package

[](#package)

[![Latest Stable Version](https://camo.githubusercontent.com/3b46b24f9c1476f17b155af46a27d144955a6d994c735876d649e2fc2d165e7b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6461796372792f706870756e69742d657874656e73696f6e2d73656c656e69756d2e7376673f6c6162656c3d737461626c65)](https://packagist.org/packages/daycry/phpunit-extension-selenium)[![Total Downloads](https://camo.githubusercontent.com/3b61f57a676571339b6998e73c9f35ebc43a7c89c6a555ed569271a6267a3936/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6461796372792f706870756e69742d657874656e73696f6e2d73656c656e69756d2e737667)](https://packagist.org/packages/daycry/phpunit-extension-selenium)[![Monthly Downloads](https://camo.githubusercontent.com/fd4582fd5e03a8a41ec172f33601a23de1796673c44f5de1df8e7be0cf011c03/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6461796372792f706870756e69742d657874656e73696f6e2d73656c656e69756d2e737667)](https://packagist.org/packages/daycry/phpunit-extension-selenium)[![PHP Version Require](https://camo.githubusercontent.com/a746eb76e47e37e6f3082be7697b80ff352126fafe468d2b88a6ec46b08d2c2b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6461796372792f706870756e69742d657874656e73696f6e2d73656c656e69756d2f7068703f636f6c6f723d383839326266)](https://packagist.org/packages/daycry/phpunit-extension-selenium)[![License](https://camo.githubusercontent.com/375d2723cc442768827e71119d7d7e108449a59028703c4328361044196b110e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6461796372792f706870756e69742d657874656e73696f6e2d73656c656e69756d)](https://github.com/daycry/phpunit-extension-selenium/blob/master/LICENSE)

### Quality

[](#quality)

[![PHPUnit](https://github.com/daycry/phpunit-extension-selenium/actions/workflows/phpunit.yml/badge.svg)](https://github.com/daycry/phpunit-extension-selenium/actions/workflows/phpunit.yml)[![PHPStan](https://github.com/daycry/phpunit-extension-selenium/actions/workflows/phpstan.yml/badge.svg)](https://github.com/daycry/phpunit-extension-selenium/actions/workflows/phpstan.yml)[![Rector](https://github.com/daycry/phpunit-extension-selenium/actions/workflows/rector.yml/badge.svg)](https://github.com/daycry/phpunit-extension-selenium/actions/workflows/rector.yml)[![Code Style](https://github.com/daycry/phpunit-extension-selenium/actions/workflows/code-style.yml/badge.svg)](https://github.com/daycry/phpunit-extension-selenium/actions/workflows/code-style.yml)[![Infection](https://github.com/daycry/phpunit-extension-selenium/actions/workflows/infection.yml/badge.svg)](https://github.com/daycry/phpunit-extension-selenium/actions/workflows/infection.yml)[![Integration](https://github.com/daycry/phpunit-extension-selenium/actions/workflows/integration.yml/badge.svg)](https://github.com/daycry/phpunit-extension-selenium/actions/workflows/integration.yml)[![Coverage Status](https://camo.githubusercontent.com/275885892e5e9339cdb215b8fc889c6c6e5baa6ed35418597787d3e42a11164c/68747470733a2f2f636f6465636f762e696f2f67682f6461796372792f706870756e69742d657874656e73696f6e2d73656c656e69756d2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/daycry/phpunit-extension-selenium)

### Community

[](#community)

[![GitHub stars](https://camo.githubusercontent.com/d117441b06f20352bc5737398007a958bbbcb8084da0289ba2eda7ed88bc42ae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6461796372792f706870756e69742d657874656e73696f6e2d73656c656e69756d3f7374796c653d736f6369616c)](https://github.com/daycry/phpunit-extension-selenium/stargazers)[![Donate](https://camo.githubusercontent.com/b57c445af971e3e99c2d0ccdbf4fa7faa4358ba27fecc8f68459b30289f82eda/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d626c75652e737667)](https://www.paypal.com/donate?business=SYC5XDT23UZ5G&no_recurring=0&item_name=Thank+you%21&currency_code=EUR)

---

Table of contents
-----------------

[](#table-of-contents)

- [Highlights](#highlights)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configure the extension](#configure-the-extension)
- [Run a Selenium hub](#run-a-selenium-hub)
- [Write your first test](#write-your-first-test)
- [Per-test overrides](#per-test-overrides)
- [Page Objects](#page-objects)
- [What you get out of the box](#what-you-get-out-of-the-box)
- [Documentation](#documentation)
- [Versioning and migrations](#versioning-and-migrations)
- [Contributing](#contributing)
- [License](#license)

Highlights
----------

[](#highlights)

- **Opt-in attribute**: `#[UseSelenium]` at class or method level — no driver cost for unmarked tests.
- **Per-test sessions** isolated through a scoped `SeleniumContext`, no static singletons, parallel-safe.
- **Multi-browser**: typed capabilities + factories for Chrome / Firefox / Edge / Safari, selectable via XML, env vars or attribute argument.
- **Fluent `Browser` facade** with typed `Locator`s (`id`, `css`, `xpath`, `testId`, `text`, `role`, `name`…).
- **Wait builder** with timeouts, polling, custom messages, retry-aware exceptions.
- **Custom assertions** (`assertVisible`, `assertText`, `assertUrlContains`, `assertCookie`, …) integrated with PHPUnit's counter.
- **Page Object base** + **Component** scope for reusable UI fragments.
- **Form helpers**: `Select`, `Upload`, `Date`, `fillForm()`.
- **Cookies / localStorage / sessionStorage** wrappers.
- **Frames / windows / alerts** via `withinFrame()`, `acceptAlert()` …
- **PSR-3 logging** end-to-end (Bootstrap → Start → Action → Finish/Failed).
- **Allure** integration as opt-in dependency; screenshots, capabilities and console logs attached to failed tests.
- **Configurable retries** with exponential backoff + jitter for flaky interactions (`StaleElementReferenceException` and friends).
- **Layered configuration**: env vars &gt; `phpunit.xml` &gt; built-in defaults.

Requirements
------------

[](#requirements)

ComponentVersionPHP`^8.2`PHPUnit`^10.0 || ^11.0`php-webdriver/webdriver`^1.15` (transitive)A reachable Selenium hub`4.x``php-webdriver/webdriver` is pulled in as a transitive dependency — you do not need to install it separately.

Installation
------------

[](#installation)

```
composer require --dev daycry/phpunit-extension-selenium
```

That's the only mandatory step. Optional extras:

```
# Allure reporting (screenshots + console logs attached to failed tests)
composer require --dev allure-framework/allure-phpunit

# Mutation testing for your own suite (already a dev-dep of this lib in
# its own repo, but you may want it for downstream CI as well)
composer require --dev infection/infection
```

If you don't install `allure-phpunit`, the Allure integration silently degrades to a no-op — your tests keep running unchanged. See [`docs/observability.md`](docs/observability.md) for the full reporting setup.

Configure the extension
-----------------------

[](#configure-the-extension)

Register `SeleniumExtension` in your `phpunit.xml` (or `phpunit.xml.dist`):

```

            tests

```

Every parameter is optional and can also be driven through environment variables (env wins over XML wins over defaults). The full list lives in [`docs/configuration.md`](docs/configuration.md).

Run a Selenium hub
------------------

[](#run-a-selenium-hub)

The simplest local setup uses Selenium's official standalone images:

```
# Chrome
docker run --rm -p 4444:4444 --shm-size=2g selenium/standalone-chrome:4

# Firefox
docker run --rm -p 4444:4444 --shm-size=2g selenium/standalone-firefox:4

# Edge
docker run --rm -p 4444:4444 --shm-size=2g selenium/standalone-edge:4
```

For multi-browser CI runs, see the reference setup in [`.github/workflows/integration.yml`](.github/workflows/integration.yml)and the longer write-up in [`docs/browsers.md`](docs/browsers.md).

Write your first test
---------------------

[](#write-your-first-test)

```
