Merge pull request #21 from eDiasoft/selenium4

Support Selenium4
This commit is contained in:
Yozhef
2023-09-12 12:47:30 +03:00
committed by GitHub
2 changed files with 117 additions and 0 deletions

View File

@@ -0,0 +1,115 @@
<?php
/*
* This file is part of the Behat MinkExtension.
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Behat\MinkExtension\ServiceContainer\Driver;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\Definition;
class Selenium4Factory implements DriverFactory
{
/**
* {@inheritdoc}
*/
public function getDriverName()
{
return 'selenium4';
}
/**
* {@inheritdoc}
*/
public function supportsJavascript()
{
return true;
}
/**
* {@inheritdoc}
*/
public function configure(ArrayNodeDefinition $builder)
{
$builder
->children()
->scalarNode('name')->defaultValue('Behat Test')->end()
->scalarNode('browser')->defaultValue('%mink.browser_name%')->end()
->append($this->getCapabilitiesNode())
->scalarNode('wd_host')->defaultValue('http://localhost:4444/wd/hub')->end()
->end()
;
}
/**
* {@inheritdoc}
*/
public function buildDriver(array $config)
{
if (!class_exists('Behat\Mink\Driver\Selenium4Driver')) {
throw new \RuntimeException(sprintf(
'Install MinkSelenium4Driver in order to use %s driver.',
$this->getDriverName()
));
}
$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,
$config['wd_host'],
));
}
protected function getCapabilitiesNode()
{
$node = new ArrayNodeDefinition('capabilities');
$node
->addDefaultsIfNotSet()
->normalizeKeys(false)
->children()
->arrayNode('firstMatch')
->end()
->arrayNode('alwaysMatch')
->children()
->scalarNode('browserName')->end()
->scalarNode('pageLoadStrategy')->end()
->arrayNode('goog:chromeOptions')
->children()
->arrayNode('extensions')
->scalarPrototype()->end()
->end()
->arrayNode('args')
->scalarPrototype()->end()
->end()
->end()
->end()
->end()
->end()
->end();
return $node;
}
}

View File

@@ -19,6 +19,7 @@ use Behat\MinkExtension\ServiceContainer\Driver\GoutteFactory;
use Behat\MinkExtension\ServiceContainer\Driver\SahiFactory; use Behat\MinkExtension\ServiceContainer\Driver\SahiFactory;
use Behat\MinkExtension\ServiceContainer\Driver\SauceLabsFactory; 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\SeleniumFactory; use Behat\MinkExtension\ServiceContainer\Driver\SeleniumFactory;
use Behat\MinkExtension\ServiceContainer\Driver\ZombieFactory; use Behat\MinkExtension\ServiceContainer\Driver\ZombieFactory;
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension; use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension;
@@ -56,6 +57,7 @@ class MinkExtension implements ExtensionInterface
$this->registerDriverFactory(new SahiFactory()); $this->registerDriverFactory(new SahiFactory());
$this->registerDriverFactory(new SeleniumFactory()); $this->registerDriverFactory(new SeleniumFactory());
$this->registerDriverFactory(new Selenium2Factory()); $this->registerDriverFactory(new Selenium2Factory());
$this->registerDriverFactory(new Selenium4Factory());
$this->registerDriverFactory(new SauceLabsFactory()); $this->registerDriverFactory(new SauceLabsFactory());
$this->registerDriverFactory(new BrowserStackFactory()); $this->registerDriverFactory(new BrowserStackFactory());
$this->registerDriverFactory(new ZombieFactory()); $this->registerDriverFactory(new ZombieFactory());