behat-chrome/chrome-mink-driver

This package is abandoned and no longer maintained. The author suggests using the dmore/chrome-mink-driver package instead.

Mink driver for controlling chrome without selenium


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

OptionValue
downloadBehaviorallow, default, deny
downloadPathe.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

OptionValueDescription
socketTimeoutint, default: 10Connection timeout in seconds
domWaitTimeoutint, default: 3000DOM 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.