dmore / chrome-mink-driver
Mink driver for controlling chrome without selenium
Requires
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- behat/mink: ^1.9
- phrity/websocket: ^1.7.0
Requires (Dev)
- mink/driver-testsuite: dev-master
- phpunit/phpunit: ^8.5.22 || ^9.5.11
- squizlabs/php_codesniffer: ^3.5
- dev-main
- 2.9.3
- 2.9.2
- 2.9.1
- 2.9.0
- 2.8.1
- 2.8.1-beta1
- 2.8.0
- 2.8.0-beta
- 2.7.0
- 2.6.4
- 2.6.3
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.0
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.1
- 2.3.0
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.1
- 1.0.0
- dev-154-mink-test-update
- dev-153-php-versions
- dev-100-iframe-test2
- dev-developing-docs
- dev-151-configure-microwaits
- dev-150-configure-microwaits
- dev-undo-abdbe629
- dev-cs-100
- dev-semantic-release
- dev-chrome-hostname-devtools-access
- dev-lennardw-master-patch-36110
- dev-coding-standards
- dev-111-event-tests-and-fix
- dev-ci-fixes
- dev-new_client
- dev-fix-click
This package is auto-updated.
Last update: 2024-10-14 00:02:57 UTC
README
Mink driver for controlling Chrome without the overhead of Selenium.
It communicates directly with Google 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 (v59+):
google-chrome-unstable --disable-gpu --headless --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222
It is recommended to start Chrome with the --disable-extensions
flag.
See https://gitlab.com/DMore/behat-chrome-skeleton for a fully working example.
Contributing
Contributions are welcome! Use the issue queue and merge requests to propose changes. Please refer to Gitlab documentation for how to use the Gitlab interface.
- To report an issue (bug, feature request etc) use the issue queue.
- If you are reporting a potential security issue, please check "This issue is confidential" when reporting the issue to the project.
- To propose code changes or a solution for an issue, use merge requests.
- Test coverage is executed on merge requests. Contributions should extend test coverage where possible and ensure all tests pass.
- Coding standards checks are executed on merge requests. Contributions should maintain coding standards.
Tests
The project has test coverage, which you can execute using the commands below.
Test execution requires a webserver configured to serve fixtures from minkphp/driver-testsuite, which is provided by a docker image from the related behat-chrome/docker-chrome-headless project. Tests executed are both tests specific to this driver and the more comprehensive test suite from mink/driver-testsuite, which is the common testsuite to ensure consistency across Mink driver implementations.
Using make
command | purpose |
---|---|
make install | Install dependencies with composer |
make test | Run tests with phpunit |
make phpcbf | Tidy code using phpcbf |
make phpcs | Check coding standards with phpcs |
Without make
To perform these tasks without make
, you can execute the same commands as above in a container. To run the tests using phpunit
:
docker run --rm -it -v .:/code -e DOCROOT=/code/vendor/mink/driver-testsuite/web-fixtures registry.gitlab.com/behat-chrome/docker-chrome-headless bash
then, in the container shell:
composer install
vendor/bin/phpunit
Versioning & releases
- Releases are distributed through Packagist at https://packagist.org/packages/dmore/chrome-mink-driver
- This project aims to follow Semantic Versioning.
- Releases are communicated using release co-ordination issues in Gitlab.
- New releases are created via git tags being pushed to Gitlab.
Usage
use Behat\Mink\Mink;
use Behat\Mink\Session;
use DMore\ChromeDriver\ChromeDriver;
$mink = new Mink([
'browser' => new Session(new ChromeDriver('http://localhost:9222', null, 'http://www.google.com'))
]);
Configuration
Option | Value | Description |
---|---|---|
socketTimeout | int, default: 10 | Connection timeout (seconds) |
domWaitTimeout | int, default: 3000 | DOM ready waiting timeout (milliseconds) |
downloadBehavior | allow, default, deny | Chrome switch to permit downloads. (v62+) |
downloadPath | e.g. /tmp/ (the default) | Where to download files to, if permitted. |
Pass configuration values as the third parameter to new ChromeDriver()
.
Rendering PDF and Screenshots
Despite the Mink functionality the driver supports printing PDF pages or capturing a screenshot.
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'))
));
$mink->setDefaultSessionName('browser');
$mink->getSession()->visit('https://gitlab.com/behat-chrome/chrome-mink-driver/blob/master/README.md');
$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
Screenshots are supported using the Mink driver interface method getScreenshot()
.
Related projects
Behat extension
To use this driver with Behat, try the dmore/behat-chrome-extension
Behat extension.
Docker image
A Docker image is used to execute tests against the targeted browser(s), and includes recent Chrome Stable, Chrome Beta and Chromium.