Merge pull request #26 from uuf6429/feature/implement-webdriver-classic-extension
Implement WebdriverClassicDriver factory
This commit is contained in:
@@ -28,7 +28,8 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"behat/mink-goutte-driver": "^1.1 || ^2.0",
|
"behat/mink-goutte-driver": "^1.1 || ^2.0",
|
||||||
"phpspec/phpspec": "^6.0 || ^7.0 || 7.1.x-dev"
|
"phpspec/phpspec": "^6.0 || ^7.0 || 7.1.x-dev",
|
||||||
|
"mink/webdriver-classic-driver": "^1.0@dev"
|
||||||
},
|
},
|
||||||
"replace": {
|
"replace": {
|
||||||
"behat/mink-extension": "self.version"
|
"behat/mink-extension": "self.version"
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace spec\Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use PhpSpec\ObjectBehavior;
|
||||||
|
use Behat\MinkExtension\ServiceContainer\Driver\DriverFactory;
|
||||||
|
|
||||||
|
class WebdriverClassicFactorySpec extends ObjectBehavior
|
||||||
|
{
|
||||||
|
public function it_is_a_driver_factory(): void
|
||||||
|
{
|
||||||
|
$this->shouldHaveType(DriverFactory::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function it_is_named_webdriver_classic(): void
|
||||||
|
{
|
||||||
|
$this->getDriverName()->shouldReturn('webdriver_classic');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function it_supports_javascript(): void
|
||||||
|
{
|
||||||
|
$this->supportsJavascript()->shouldBe(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
class Selenium2Factory implements DriverFactory
|
||||||
{
|
{
|
||||||
|
use EnvironmentCapabilities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@@ -60,27 +62,9 @@ class Selenium2Factory implements DriverFactory
|
|||||||
$extraCapabilities = $config['capabilities']['extra_capabilities'];
|
$extraCapabilities = $config['capabilities']['extra_capabilities'];
|
||||||
unset($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(
|
return new Definition('Behat\Mink\Driver\Selenium2Driver', array(
|
||||||
$config['browser'],
|
$config['browser'],
|
||||||
array_replace($guessedCapabilities, $extraCapabilities, $config['capabilities']),
|
array_replace($this->guessEnvironmentCapabilities(), $extraCapabilities, $config['capabilities']),
|
||||||
$config['wd_host'],
|
$config['wd_host'],
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ use Symfony\Component\DependencyInjection\Definition;
|
|||||||
|
|
||||||
class Selenium4Factory implements DriverFactory
|
class Selenium4Factory implements DriverFactory
|
||||||
{
|
{
|
||||||
|
use EnvironmentCapabilities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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(
|
return new Definition('Behat\Mink\Driver\Selenium4Driver', array(
|
||||||
$config['browser'],
|
$config['browser'],
|
||||||
$args,
|
array_merge(
|
||||||
|
$this->guessEnvironmentCapabilities(),
|
||||||
|
$config['capabilities']
|
||||||
|
),
|
||||||
$config['wd_host'],
|
$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(
|
||||||
|
$this->guessEnvironmentCapabilities(),
|
||||||
|
$config['capabilities']
|
||||||
|
),
|
||||||
|
$config['wd_host'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ use Behat\MinkExtension\ServiceContainer\Driver\SauceLabsFactory;
|
|||||||
use Behat\MinkExtension\ServiceContainer\Driver\Selenium2Factory;
|
use Behat\MinkExtension\ServiceContainer\Driver\Selenium2Factory;
|
||||||
use Behat\MinkExtension\ServiceContainer\Driver\Selenium4Factory;
|
use Behat\MinkExtension\ServiceContainer\Driver\Selenium4Factory;
|
||||||
use Behat\MinkExtension\ServiceContainer\Driver\SeleniumFactory;
|
use Behat\MinkExtension\ServiceContainer\Driver\SeleniumFactory;
|
||||||
|
use Behat\MinkExtension\ServiceContainer\Driver\WebdriverClassicFactory;
|
||||||
use Behat\MinkExtension\ServiceContainer\Driver\ZombieFactory;
|
use Behat\MinkExtension\ServiceContainer\Driver\ZombieFactory;
|
||||||
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension;
|
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension;
|
||||||
use Behat\Testwork\ServiceContainer\Exception\ProcessingException;
|
use Behat\Testwork\ServiceContainer\Exception\ProcessingException;
|
||||||
@@ -62,6 +63,7 @@ class MinkExtension implements ExtensionInterface
|
|||||||
$this->registerDriverFactory(new BrowserStackFactory());
|
$this->registerDriverFactory(new BrowserStackFactory());
|
||||||
$this->registerDriverFactory(new ZombieFactory());
|
$this->registerDriverFactory(new ZombieFactory());
|
||||||
$this->registerDriverFactory(new AppiumFactory());
|
$this->registerDriverFactory(new AppiumFactory());
|
||||||
|
$this->registerDriverFactory(new WebdriverClassicFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerDriverFactory(DriverFactory $driverFactory)
|
public function registerDriverFactory(DriverFactory $driverFactory)
|
||||||
|
|||||||
Reference in New Issue
Block a user