phpunit/phpunit-selenium
PHPUnit-Selenium provides a Selenium2TestCase for running end-to-end browser tests with Selenium 2 in PHPUnit. Install via Composer and use version lines aligned to PHPUnit/PHP (e.g., 9.x for PHPUnit 9 on PHP 7.3+).
Pros:
Selenium2TestCase can be subclassed for custom test logic (e.g., Laravel-specific assertions or hooks).Cons:
laravel/framework).--dev), isolated from production dependencies.phpunit --testsuite=Selenium).chromedriver, geckodriver).
Mitigation: Automate setup via Docker or Laravel Sail.phpunit.xml configuration)?phpunit.xml (no conflicts).Selenium2TestCase into test helpers).selenium/standalone-chrome image).phpunit/phpunit-selenium to composer.json (--dev).Selenium2TestCase subclass in tests/Feature/SeleniumTest.php.use PHPUnit_Selenium2TestCase;
class ExampleSeleniumTest extends Selenium2TestCase {
protected function setUp() {
$this->setBrowser('chrome');
$this->setBrowserUrl('http://laravel.test');
}
public function testLoginFlow() {
$this->open('/login');
$this->type('email', 'user@example.com');
$this->click('button[type=submit]');
$this->assertContains('Dashboard', $this->getTitle());
}
}
# docker-compose.yml
services:
selenium:
image: selenium/standalone-chrome
ports:
- "4444:4444"
laravel.test:
build: .
ports:
- "8000:8000"
phpunit.xml to include Selenium tests:
<testsuites>
<testsuite name="Feature">
<directory>./tests/Feature</directory>
</testsuite>
<testsuite name="Selenium">
<directory>./tests/Selenium</directory>
</testsuite>
</testsuites>
php artisan selenium:start).RefreshDatabase trait to reset test data before Selenium tests.actingAs() or session-based auth in Selenium tests.composer outdated and CI checks for version drift.Http::fake()).laravel-debugbar or Selenium’s built-in debugging.SELENIUM.md guide in the repo.--parallel flag or CI matrix.| Failure Type | Impact | Mitigation |
|---|---|---|
| Flaky Tests | False negatives/positives | Explicit waits, retries, headless mode |
| Selenium Server Crash | Blocked CI/CD pipelines | Health checks, auto-restart, fallback to local |
| Browser Incompatibility | Tests pass locally but fail in CI | Use CI-specific browser matrices |
| Network Latency | Timeouts in cloud environments | Increase timeouts, use regional test nodes |
| Test Data Corruption | Inconsistent test states | Transactional test databases, fresh VMs |
How can I help you explore Laravel packages today?