diff --git a/composer.json b/composer.json index 5d70385..f5b46f4 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ }, "require-dev": { "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": { "behat/mink-extension": "self.version" diff --git a/spec/Behat/MinkExtension/ServiceContainer/Driver/WebdriverClassicFactorySpec.php b/spec/Behat/MinkExtension/ServiceContainer/Driver/WebdriverClassicFactorySpec.php new file mode 100644 index 0000000..ddb0ca9 --- /dev/null +++ b/spec/Behat/MinkExtension/ServiceContainer/Driver/WebdriverClassicFactorySpec.php @@ -0,0 +1,24 @@ +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); + } +} diff --git a/src/Behat/MinkExtension/ServiceContainer/Driver/EnvironmentCapabilities.php b/src/Behat/MinkExtension/ServiceContainer/Driver/EnvironmentCapabilities.php new file mode 100644 index 0000000..ddba7a4 --- /dev/null +++ b/src/Behat/MinkExtension/ServiceContainer/Driver/EnvironmentCapabilities.php @@ -0,0 +1,43 @@ + 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, + ], + ]; + } + } +} diff --git a/src/Behat/MinkExtension/ServiceContainer/Driver/Selenium2Factory.php b/src/Behat/MinkExtension/ServiceContainer/Driver/Selenium2Factory.php index 0da0564..1c57529 100644 --- a/src/Behat/MinkExtension/ServiceContainer/Driver/Selenium2Factory.php +++ b/src/Behat/MinkExtension/ServiceContainer/Driver/Selenium2Factory.php @@ -15,6 +15,8 @@ class Selenium2Factory implements DriverFactory { + use EnvironmentCapabilities; + /** * {@inheritdoc} */ @@ -60,27 +62,9 @@ public function buildDriver(array $config) $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'], )); } diff --git a/src/Behat/MinkExtension/ServiceContainer/Driver/Selenium4Factory.php b/src/Behat/MinkExtension/ServiceContainer/Driver/Selenium4Factory.php index 9e3a9f2..58a008a 100644 --- a/src/Behat/MinkExtension/ServiceContainer/Driver/Selenium4Factory.php +++ b/src/Behat/MinkExtension/ServiceContainer/Driver/Selenium4Factory.php @@ -15,6 +15,8 @@ class Selenium4Factory implements DriverFactory { + use EnvironmentCapabilities; + /** * {@inheritdoc} */ @@ -58,26 +60,12 @@ public function buildDriver(array $config) )); } - $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( + $this->guessEnvironmentCapabilities(), + $config['capabilities'] + ), $config['wd_host'], )); } diff --git a/src/Behat/MinkExtension/ServiceContainer/Driver/WebdriverClassicFactory.php b/src/Behat/MinkExtension/ServiceContainer/Driver/WebdriverClassicFactory.php new file mode 100644 index 0000000..f83ff42 --- /dev/null +++ b/src/Behat/MinkExtension/ServiceContainer/Driver/WebdriverClassicFactory.php @@ -0,0 +1,66 @@ +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'], + ]); + } +} diff --git a/src/Behat/MinkExtension/ServiceContainer/MinkExtension.php b/src/Behat/MinkExtension/ServiceContainer/MinkExtension.php index a1209f8..7a75ce5 100644 --- a/src/Behat/MinkExtension/ServiceContainer/MinkExtension.php +++ b/src/Behat/MinkExtension/ServiceContainer/MinkExtension.php @@ -21,6 +21,7 @@ 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 @@ public function __construct() $this->registerDriverFactory(new BrowserStackFactory()); $this->registerDriverFactory(new ZombieFactory()); $this->registerDriverFactory(new AppiumFactory()); + $this->registerDriverFactory(new WebdriverClassicFactory()); } public function registerDriverFactory(DriverFactory $driverFactory)