Skip to content
Snippets Groups Projects
Commit e778f7c2 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2573165 by tunic, hussainweb, elachlan, dawehner, Jaesin, grom358,...

Issue #2573165 by tunic, hussainweb, elachlan, dawehner, Jaesin, grom358, cilefen: Step 1.5: Make the driver swappable more easy
parent 766c1542
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -182,6 +182,33 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
*/
protected $customTranslations;
/*
* Mink class for the default driver to use.
*
* Shoud be a fully qualified class name that implements
* Behat\Mink\Driver\DriverInterface.
*
* Value can be overridden using the environment variable MINK_DRIVER_CLASS.
*
* @var string.
*/
protected $minkDefaultDriverClass = '\Behat\Mink\Driver\GoutteDriver';
/*
* Mink default driver params.
*
* If it's an array its contents are used as constructor params when default
* Mink driver class is instantiated.
*
* Can be overridden using the environment variable MINK_DRIVER_ARGS. In this
* case that variable should be a JSON array, for example:
* '["firefox", null, "http://localhost:4444/wd/hub"]'.
*
*
* @var array
*/
protected $minkDefaultDriverArgs;
/**
* Mink session manager.
*
......@@ -193,15 +220,51 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
* Initializes Mink sessions.
*/
protected function initMink() {
$driver = new GoutteDriver();
$driver = $this->getDefaultDriverInstance();
$session = new Session($driver);
$this->mink = new Mink();
$this->mink->registerSession('goutte', $session);
$this->mink->setDefaultSessionName('goutte');
$this->mink->registerSession('default', $session);
$this->mink->setDefaultSessionName('default');
$this->registerSessions();
return $session;
}
/**
* Gets an instance of the default Mink driver.
*
* @return Behat\Mink\Driver\DriverInterface
* Instance of default Mink driver.
*
* @throws \InvalidArgumentException
* When provided default Mink driver class can't be instantiated.
*/
protected function getDefaultDriverInstance() {
// Get default driver params from environment if availables.
if ($arg_json = getenv('MINK_DRIVER_ARGS')) {
$this->minkDefaultDriverArgs = json_decode($arg_json);
}
// Get and check default driver class from environment if availables.
if ($minkDriverClass = getenv('MINK_DRIVER_CLASS')) {
if (class_exists($minkDriverClass)) {
$this->minkDefaultDriverClass = $minkDriverClass;
}
else {
throw new \InvalidArgumentException("Can't instantiate provided $minkDriverClass class by environment as default driver class.");
}
}
if (is_array($this->minkDefaultDriverArgs)) {
// Use ReflectionClass to instantiate class with received params.
$reflector = new ReflectionClass($this->minkDefaultDriverClass);
$driver = $reflector->newInstanceArgs($this->minkDefaultDriverArgs);
}
else {
$driver = new $this->minkDefaultDriverClass();
}
return $driver;
}
/**
* Registers additional Mink sessions.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment