Installation Add the package via Composer:
composer require dmore/chrome-mink-driver
Ensure Chrome is installed and accessible via $PATH.
Basic Configuration
In config/mink.php, add the Chrome driver:
'drivers' => [
'chrome' => [
'class' => \DMore\ChromeMinkDriver\ChromeDriver::class,
'args' => [
'chromeOptions' => [
'args' => ['--headless', '--disable-gpu'],
],
],
],
],
First Use Case Use the driver in a Laravel test:
use DMore\ChromeMinkDriver\ChromeDriver;
public function testChromeDriver()
{
$driver = new ChromeDriver();
$session = $driver->start();
$session->visit('https://laravel.com');
$this->assertEquals('Laravel', $session->getTitle());
$session->quit();
}
Headless vs. Headful Testing Toggle Chrome options dynamically:
$driver->setChromeOptions(['args' => ['--no-sandbox', '--disable-dev-shm-usage']]);
Session Management Reuse sessions for multi-step tests:
$session = $driver->start();
$session->visit('/login');
// ... perform actions ...
$session->quit(); // Explicit cleanup
Integration with Laravel Testing
Extend Laravel’s BrowserKit or use Mink directly:
use Facebook\WebDriver\Remote\RemoteWebDriver;
use DMore\ChromeMinkDriver\ChromeDriver;
public function testWithMink()
{
$driver = new ChromeDriver();
$session = $driver->start();
$this->assertEquals('Home', $session->getPage()->find('css', 'h1')->getText());
}
--remote-debugging-port for manual inspection.Chrome Version Mismatch
chrome --version and check driver compatibility.Headless Mode Quirks
--disable-gpu to avoid sandbox errors in CI.Session Leaks
$session->quit() to free resources, especially in CI.try-finally blocks for cleanup:
try {
$session->visit('/admin');
} finally {
$session->quit();
}
$driver->setChromeOptions(['logPath' => storage_path('logs/chromedriver.log')]);
--remote-debugging-port=9222 and access http://localhost:9222.Connection refused: Chrome not running or port blocked.Element not found: Use explicit waits ($session->wait()).Custom ChromeOptions Override defaults per test environment:
$driver->setChromeOptions([
'args' => ['--window-size=1920,1080'],
'binary' => '/path/to/custom/chrome',
]);
Proxy Support Configure for testing behind proxies:
$driver->setChromeOptions([
'proxy' => [
'httpProxy' => 'http://proxy.example.com:8080',
'sslProxy' => 'http://proxy.example.com:8080',
],
]);
Integration with Laravel Dusk Replace Dusk’s Selenium with ChromeMink for lighter tests:
// config/dusk.php
'browser' => 'chrome',
'browserDriver' => 'chrome',
How can I help you explore Laravel packages today?