Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement WebdriverClassicDriver factory #26

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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": "dev-main"
stof marked this conversation as resolved.
Show resolved Hide resolved
uuf6429 marked this conversation as resolved.
Show resolved Hide resolved
},
"extra": {
"branch-alias": {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Behat\MinkExtension\ServiceContainer\Driver;

/**
* @internal
*/
trait EnvironmentCapabilities
uuf6429 marked this conversation as resolved.
Show resolved Hide resolved
{
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,
],
];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

class Selenium2Factory implements DriverFactory
{
use EnvironmentCapabilities;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -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'],
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

class Selenium4Factory implements DriverFactory
{
use EnvironmentCapabilities;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -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']
),
uuf6429 marked this conversation as resolved.
Show resolved Hide resolved
$config['wd_host'],
));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
uuf6429 marked this conversation as resolved.
Show resolved Hide resolved
{
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'],
]);
}
}
2 changes: 2 additions & 0 deletions src/Behat/MinkExtension/ServiceContainer/MinkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Loading