Skip to content

Commit

Permalink
Merge pull request #21 from eDiasoft/selenium4
Browse files Browse the repository at this point in the history
Support Selenium4
  • Loading branch information
Yozhef authored Sep 12, 2023
2 parents ffc5ee8 + 4f03302 commit 41213ec
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
115 changes: 115 additions & 0 deletions src/Behat/MinkExtension/ServiceContainer/Driver/Selenium4Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

/*
* This file is part of the Behat MinkExtension.
* (c) Konstantin Kudryashov <[email protected]>
*
* 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;
}
}
2 changes: 2 additions & 0 deletions src/Behat/MinkExtension/ServiceContainer/MinkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Behat\MinkExtension\ServiceContainer\Driver\SahiFactory;
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\ZombieFactory;
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension;
Expand Down Expand Up @@ -56,6 +57,7 @@ public function __construct()
$this->registerDriverFactory(new SahiFactory());
$this->registerDriverFactory(new SeleniumFactory());
$this->registerDriverFactory(new Selenium2Factory());
$this->registerDriverFactory(new Selenium4Factory());
$this->registerDriverFactory(new SauceLabsFactory());
$this->registerDriverFactory(new BrowserStackFactory());
$this->registerDriverFactory(new ZombieFactory());
Expand Down

0 comments on commit 41213ec

Please sign in to comment.