Implement WebdriverClassicDriver factory
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Behat\MinkExtension\ServiceContainer\Driver;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
trait EnvironmentCapabilities
|
||||
{
|
||||
private function guessEnvironmentCapabilities(): array
|
||||
{
|
||||
switch (true) {
|
||||
case (bool)getenv('TRAVIS_JOB_NUMBER'):
|
||||
return [
|
||||
'tunnel-identifier' => getenv('TRAVIS_JOB_NUMBER'),
|
||||
'build' => getenv('TRAVIS_BUILD_NUMBER'),
|
||||
'tags' => [
|
||||
'Travis-CI',
|
||||
'PHP ' . PHP_VERSION,
|
||||
],
|
||||
];
|
||||
|
||||
case (bool)getenv('JENKINS_HOME'):
|
||||
return [
|
||||
'tunnel-identifier' => getenv('JOB_NAME'),
|
||||
'build' => getenv('BUILD_NUMBER'),
|
||||
'tags' => [
|
||||
'Jenkins',
|
||||
'PHP ' . PHP_VERSION,
|
||||
getenv('BUILD_TAG'),
|
||||
],
|
||||
];
|
||||
|
||||
default:
|
||||
return [
|
||||
'tags' => [
|
||||
php_uname('n'),
|
||||
'PHP ' . PHP_VERSION,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
class Selenium2Factory implements DriverFactory
|
||||
{
|
||||
use EnvironmentCapabilities;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -60,27 +62,9 @@ class Selenium2Factory implements DriverFactory
|
||||
$extraCapabilities = $config['capabilities']['extra_capabilities'];
|
||||
unset($config['capabilities']['extra_capabilities']);
|
||||
|
||||
if (getenv('TRAVIS_JOB_NUMBER')) {
|
||||
$guessedCapabilities = array(
|
||||
'tunnel-identifier' => getenv('TRAVIS_JOB_NUMBER'),
|
||||
'build' => getenv('TRAVIS_BUILD_NUMBER'),
|
||||
'tags' => array('Travis-CI', 'PHP '.phpversion()),
|
||||
);
|
||||
} elseif (getenv('JENKINS_HOME')) {
|
||||
$guessedCapabilities = array(
|
||||
'tunnel-identifier' => getenv('JOB_NAME'),
|
||||
'build' => getenv('BUILD_NUMBER'),
|
||||
'tags' => array('Jenkins', 'PHP '.phpversion(), getenv('BUILD_TAG')),
|
||||
);
|
||||
} else {
|
||||
$guessedCapabilities = array(
|
||||
'tags' => array(php_uname('n'), 'PHP '.phpversion()),
|
||||
);
|
||||
}
|
||||
|
||||
return new Definition('Behat\Mink\Driver\Selenium2Driver', array(
|
||||
$config['browser'],
|
||||
array_replace($guessedCapabilities, $extraCapabilities, $config['capabilities']),
|
||||
array_replace($this->guessEnvironmentCapabilities(), $extraCapabilities, $config['capabilities']),
|
||||
$config['wd_host'],
|
||||
));
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
class Selenium4Factory implements DriverFactory
|
||||
{
|
||||
use EnvironmentCapabilities;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -58,26 +60,12 @@ class Selenium4Factory implements DriverFactory
|
||||
));
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'capabilities' => $config['capabilities'],
|
||||
'tags' => array(php_uname('n'), 'PHP '.phpversion())
|
||||
);
|
||||
|
||||
if (getenv('TRAVIS_JOB_NUMBER')) {
|
||||
$args['tunnel-identifier'] = getenv('TRAVIS_JOB_NUMBER');
|
||||
$args['build'] = getenv('TRAVIS_BUILD_NUMBER');
|
||||
$args['tags'] = array('Travis-CI', 'PHP '.phpversion());
|
||||
}
|
||||
|
||||
if (getenv('JENKINS_HOME')) {
|
||||
$args['tunnel-identifier'] = getenv('JOB_NAME');
|
||||
$args['build'] = getenv('BUILD_NUMBER');
|
||||
$args['tags'] = array('Jenkins', 'PHP '.phpversion(), getenv('BUILD_TAG'));
|
||||
}
|
||||
|
||||
return new Definition('Behat\Mink\Driver\Selenium4Driver', array(
|
||||
$config['browser'],
|
||||
$args,
|
||||
array_merge(
|
||||
['capabilities' => $config['capabilities']],
|
||||
$this->guessEnvironmentCapabilities()
|
||||
),
|
||||
$config['wd_host'],
|
||||
));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Behat\MinkExtension\ServiceContainer\Driver;
|
||||
|
||||
use Mink\WebdriverClassicDriver\WebdriverClassicDriver;
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
class WebdriverClassicFactory implements DriverFactory
|
||||
{
|
||||
use EnvironmentCapabilities;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDriverName(): string
|
||||
{
|
||||
return 'webdriver-classic';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsJavascript(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configure(ArrayNodeDefinition $builder): void
|
||||
{
|
||||
$builder
|
||||
->children()
|
||||
->scalarNode('browser')->defaultValue('%mink.browser_name%')->end()
|
||||
->scalarNode('wd_host')->defaultValue('http://localhost:4444/wd/hub')->end()
|
||||
->arrayNode('capabilities')
|
||||
->normalizeKeys(false)
|
||||
->useAttributeAsKey('name')
|
||||
->prototype('variable')->end()
|
||||
->end()
|
||||
->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildDriver(array $config): Definition
|
||||
{
|
||||
if (!class_exists(WebdriverClassicDriver::class)) {
|
||||
throw new \RuntimeException(
|
||||
"Install mink/webdriver-classic-driver in order to use the {$this->getDriverName()} driver."
|
||||
);
|
||||
}
|
||||
|
||||
return new Definition(WebdriverClassicDriver::class, [
|
||||
$config['browser'],
|
||||
array_merge(
|
||||
['capabilities' => $config['capabilities']],
|
||||
$this->guessEnvironmentCapabilities()
|
||||
),
|
||||
$config['wd_host'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ use Behat\MinkExtension\ServiceContainer\Driver\SauceLabsFactory;
|
||||
use Behat\MinkExtension\ServiceContainer\Driver\Selenium2Factory;
|
||||
use Behat\MinkExtension\ServiceContainer\Driver\Selenium4Factory;
|
||||
use Behat\MinkExtension\ServiceContainer\Driver\SeleniumFactory;
|
||||
use Behat\MinkExtension\ServiceContainer\Driver\WebdriverClassicFactory;
|
||||
use Behat\MinkExtension\ServiceContainer\Driver\ZombieFactory;
|
||||
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension;
|
||||
use Behat\Testwork\ServiceContainer\Exception\ProcessingException;
|
||||
@@ -62,6 +63,7 @@ class MinkExtension implements ExtensionInterface
|
||||
$this->registerDriverFactory(new BrowserStackFactory());
|
||||
$this->registerDriverFactory(new ZombieFactory());
|
||||
$this->registerDriverFactory(new AppiumFactory());
|
||||
$this->registerDriverFactory(new WebdriverClassicFactory());
|
||||
}
|
||||
|
||||
public function registerDriverFactory(DriverFactory $driverFactory)
|
||||
|
||||
Reference in New Issue
Block a user