forked from Behat/MinkExtension
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from uuf6429/feature/implement-webdriver-class…
…ic-extension Implement WebdriverClassicDriver factory
- Loading branch information
Showing
7 changed files
with
146 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
spec/Behat/MinkExtension/ServiceContainer/Driver/WebdriverClassicFactorySpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Behat/MinkExtension/ServiceContainer/Driver/EnvironmentCapabilities.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Behat\MinkExtension\ServiceContainer\Driver; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
trait EnvironmentCapabilities | ||
{ | ||
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, | ||
], | ||
]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/Behat/MinkExtension/ServiceContainer/Driver/WebdriverClassicFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
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'], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters