This commit is contained in:
Shu Chen
2023-07-10 15:43:15 +08:00
parent 59f3cf104a
commit a846a31b58
2 changed files with 34 additions and 90 deletions

View File

@@ -38,6 +38,7 @@ class Selenium4Factory implements DriverFactory
{ {
$builder $builder
->children() ->children()
->scalarNode('name')->defaultValue('Behat Test')->end()
->scalarNode('browser')->defaultValue('%mink.browser_name%')->end() ->scalarNode('browser')->defaultValue('%mink.browser_name%')->end()
->append($this->getCapabilitiesNode()) ->append($this->getCapabilitiesNode())
->scalarNode('wd_host')->defaultValue('http://localhost:4444/wd/hub')->end() ->scalarNode('wd_host')->defaultValue('http://localhost:4444/wd/hub')->end()
@@ -50,37 +51,35 @@ class Selenium4Factory implements DriverFactory
*/ */
public function buildDriver(array $config) public function buildDriver(array $config)
{ {
if (!class_exists('Behat\Mink\Driver\Selenium2Driver')) { if (!class_exists('Behat\Mink\Driver\Selenium4Driver')) {
throw new \RuntimeException(sprintf( throw new \RuntimeException(sprintf(
'Install MinkSelenium2Driver in order to use %s driver.', 'Install MinkSelenium4Driver in order to use %s driver.',
$this->getDriverName() $this->getDriverName()
)); ));
} }
$extraCapabilities = $config['capabilities']['extra_capabilities']; dd($config);
unset($config['capabilities']['extra_capabilities']);
$desiredCapabilities = array(
'capabilities' => $config['capabilities'],
'tags' => array(php_uname('n'), 'PHP '.phpversion())
);
if (getenv('TRAVIS_JOB_NUMBER')) { if (getenv('TRAVIS_JOB_NUMBER')) {
$guessedCapabilities = array( $desiredCapabilities['tunnel-identifier'] = getenv('TRAVIS_JOB_NUMBER');
'tunnel-identifier' => getenv('TRAVIS_JOB_NUMBER'), $desiredCapabilities['build'] = getenv('TRAVIS_BUILD_NUMBER');
'build' => getenv('TRAVIS_BUILD_NUMBER'), $desiredCapabilities['tags'] = array('Travis-CI', 'PHP '.phpversion());
'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( if (getenv('JENKINS_HOME')) {
$desiredCapabilities['tunnel-identifier'] = getenv('JOB_NAME');
$desiredCapabilities['build'] = getenv('BUILD_NUMBER');
$desiredCapabilities['tags'] = array('Jenkins', 'PHP '.phpversion(), getenv('BUILD_TAG'));
}
dd($config['capabilities']);
return new Definition('Behat\Mink\Driver\Selenium4Driver', array(
$config['browser'], $config['browser'],
array_replace($guessedCapabilities, $extraCapabilities, $config['capabilities']), $desiredCapabilities,
$config['wd_host'], $config['wd_host'],
)); ));
} }
@@ -92,81 +91,24 @@ class Selenium4Factory implements DriverFactory
$node $node
->addDefaultsIfNotSet() ->addDefaultsIfNotSet()
->normalizeKeys(false) ->normalizeKeys(false)
->children()
->arrayNode('firstMatch')
->end()
->arrayNode('alwaysMatch')
->children() ->children()
->scalarNode('browserName')->end() ->scalarNode('browserName')->end()
->scalarNode('version')->end() ->scalarNode('pageLoadStrategy')->end()
->scalarNode('platform')->end() ->arrayNode('goog:chromeOptions')
->scalarNode('browserVersion')->end()
->scalarNode('browser')->defaultValue('firefox')->end()
->booleanNode('marionette')->end()
->booleanNode('ignoreZoomSetting')->defaultFalse()->end()
->scalarNode('name')->defaultValue('Behat feature suite')->end()
->scalarNode('deviceOrientation')->end()
->scalarNode('deviceType')->end()
->booleanNode('javascriptEnabled')->end()
->booleanNode('databaseEnabled')->end()
->booleanNode('locationContextEnabled')->end()
->booleanNode('applicationCacheEnabled')->end()
->booleanNode('browserConnectionEnabled')->end()
->booleanNode('webStorageEnabled')->end()
->booleanNode('rotatable')->end()
->booleanNode('acceptSslCerts')->end()
->booleanNode('nativeEvents')->end()
->booleanNode('overlappingCheckDisabled')->end()
->arrayNode('proxy')
->children() ->children()
->scalarNode('proxyType')->end() ->arrayNode('extensions')
->scalarNode('proxyAuthconfigUrl')->end() ->scalarPrototype()->end()
->scalarNode('ftpProxy')->end()
->scalarNode('httpProxy')->end()
->scalarNode('sslProxy')->end()
->end() ->end()
->validate() ->arrayNode('args')
->ifTrue(function ($v) { ->scalarPrototype()->end()
return empty($v);
})
->thenUnset()
->end() ->end()
->end() ->end()
->arrayNode('firefox')
->children()
->scalarNode('profile')
->validate()
->ifTrue(function ($v) {
return !file_exists($v);
})
->thenInvalid('Cannot find profile zip file %s')
->end() ->end()
->end() ->end()
->scalarNode('binary')->end()
->end()
->end()
->arrayNode('chrome')
->children()
->arrayNode('switches')->prototype('scalar')->end()->end()
->scalarNode('binary')->end()
->arrayNode('extensions')->prototype('scalar')->end()->end()
->arrayNode('prefs')
->normalizeKeys(false)
->useAttributeAsKey('name')
->prototype('variable')->end()
->end()
->end()
->validate()
->ifTrue(function ($v) {
return empty($v['prefs']);
})
->then(function ($v) {
unset($v['prefs']);
return $v;
})
->end()
->end()
->arrayNode('extra_capabilities')
->info('Custom capabilities merged with the known ones')
->normalizeKeys(false)
->useAttributeAsKey('name')
->prototype('variable')->end()
->end() ->end()
->end(); ->end();

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());