behat-chrome / chrome-mink-driver
Mink driver for controlling chrome without selenium
Requires
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- behat/mink: ^1.7
- textalk/websocket: ^1.2.0
Requires (Dev)
- mink/driver-testsuite: dev-master
- phpunit/phpunit: ^5.0.0
- squizlabs/php_codesniffer: ^3.5
- dev-main
- 3.0.x-dev
- 2.8.0
- dev-master / 2.0.x-dev
- dev-155-readme
- dev-155-remote-chrome
- dev-121-rename-to-behat-chrome
- dev-develop
- dev-lint-fixes
- dev-114-coding_standards_fix
- dev-86-cookie_encoding
- dev-dev-2.9.0
- dev-116-phpunit-update
- dev-108-php7.4_8.0
- dev-combined-108
- dev-normalize-composer.json
- dev-fix-chromebrowser-test-name
- dev-107-enlightn_security-checker
- dev-extend-stream-read-exception-information
- dev-94-start_before_actions
- dev-104-code_style_checks
- dev-77-chrome_hostname_devtools_access
- dev-code_style
- dev-103-start_before_setBasicAuth
- dev-ci-fixes
- dev-stream-read-exception
- dev-new_client
- dev-improved-ci
- dev-revert-ce7b501e
- dev-fix-maximize-on-headless
- dev-Issue-32
- dev-fix-click
This package is auto-updated.
Last update: 2024-09-13 20:10:02 UTC
README
Please continue to use dmore/chrome-mink-driver via Packagist
See https://gitlab.com/behat-chrome/chrome-mink-driver/-/issues/121 for details.
In short: I created placeholder Packagist packages in the behat-chrome/* namespace as part of that issue. DMore and I then decided to retain the original Packagist name , but a few folks appear to have picked up on the new Packagist name.
The Gitlab projects only are moved to https://gitlab.com/behat-chrome/
To undo the composer change:
composer remove behat-chrome/behat-chrome-extension behat-chrome/chrome-mink-driver
composer require dmore/behat-chrome-extension dmore/chrome-mink-driver
The behat-chrome/ packages on Packagist are now marked abandoned and point people back to dmore/
README continues
Mink driver for controlling chrome without the overhead of selenium.
It communicates directly with chrome over HTTP and WebSockets, which allows it to work at least twice as fast as chrome with selenium.
For chrome 59+ it supports headless mode, eliminating the need to install a display server, and the overhead that comes with it.
This driver is tested and benchmarked against a behat suite of 1800 scenarios and 19000 steps. It can successfully run it in less than 18 minutes with chrome 60 headless.
The same suite running against chrome 58 with xvfb and selenium takes ~60 minutes.
Installation:
composer require dmore/chrome-mink-driver
Requirements:
- Google chrome or chromium running with remote debugging
Example:
google-chrome-stable --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222
or headless (59+):
google-chrome-unstable --disable-gpu --headless --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222
The official docker image includes chrome 60 running headless.
See https://gitlab.com/DMore/behat-chrome-skeleton for a fully working example.
Usage:
use Behat\Mink\Mink;
use Behat\Mink\Session;
use DMore\ChromeDriver\ChromeDriver;
$mink = new Mink(array(
'browser' => new Session(new ChromeDriver('http://localhost:9222', null, 'http://www.google.com'))
));
Since Chrome 62+ there is the experimental option to allow file downloads which can be triggered with options being passed to the ChromeDriver
Option | Value |
---|---|
downloadBehavior | allow, default, deny |
downloadPath | e.g. /tmp/ (/tmp/ is the default |
Usage:
use Behat\Mink\Mink;
use Behat\Mink\Session;
use DMore\ChromeDriver\ChromeDriver;
use Selenium\Client as SeleniumClient;
$mink = new Mink(array(
'chrome' => new Session(new ChromeDriver('http://localhost:9222', null, 'http://www.google.com', ['downloadBehavior' => 'allow', 'downloadPath' => '/tmp/'])),
));
Besides the above mentioned download options the following options can be provided
Option | Value | Description |
---|---|---|
socketTimeout | int, default: 10 | Connection timeout in seconds |
domWaitTimeout | int, default: 3000 | DOM ready waiting timeout in milliseconds |
Rendering PDF and Screenshots
Despite the Mink functionality the driver supports printing PDF pages or capturing a screenshot.
Usage:
use Behat\Mink\Mink;
use Behat\Mink\Session;
use DMore\ChromeDriver\ChromeDriver;
$mink = new Mink(array(
'browser' => new Session(new ChromeDriver('http://localhost:9222', null, 'http://www.google.com'))
));
// set the default session name
$mink->setDefaultSessionName('browser');
// visit a page
$mink->getSession()->visit('https://gitlab.com/DMore/chrome-mink-driver/blob/master/README.md');
/** @var ChromeDriver $driver */
$driver = $mink->getSession()->getDriver();
$driver->printToPdf('/tmp/readme.pdf');
The available options are documented here: https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF
You can capture a screenshot with the captueScreenshot
method. Options are documented here.
Please note, it is recommended to start Chrome with the disable-extensions flag like:
google-chrome-stable --disable-gpu --headless --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222 --window-size="1920,1080" --disable-extensions
Behat
See the behat extension if you want to use this driver with behat.
Contributing
You are encouraged to fork this repository and contribute your own improvements.
See the contribution guide for instructions.