Skip to content

Commit

Permalink
Add support for php-webdriver/webdriver >= 1.15.0 #16
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfausk committed May 7, 2024
1 parent 42b9ad8 commit 402b413
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
vx.x.x / 2024-xx-xx
===================

v1.1.3 / 2024-05-07
===================

Fixes:
* Ensure support for ```php-webdriver/webdriver >= 1.15.0``` #16

Thanks for report and investigation to @validaide-mark-bijl

v1.1.2 / 2024-04-18
===================

Expand Down
12 changes: 6 additions & 6 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ friends-of-behat/mink-extension v2.5.0 MIT
php-webdriver/webdriver 1.15.1 MIT
psr/container 1.1.2 MIT
psr/log 2.0.0 MIT
robertfausk/mink-panther-driver v1.1.0 MIT
symfony/browser-kit v5.4.35 MIT
robertfausk/mink-panther-driver v1.1.1 MIT
symfony/browser-kit v5.4.39 MIT
symfony/config v3.4.47 MIT
symfony/console v4.4.49 MIT
symfony/css-selector v7.0.3 MIT
symfony/css-selector v7.0.7 MIT
symfony/dependency-injection v3.4.47 MIT
symfony/deprecation-contracts v2.5.3 MIT
symfony/dom-crawler v5.4.35 MIT
symfony/dom-crawler v5.4.39 MIT
symfony/event-dispatcher v4.4.44 MIT
symfony/event-dispatcher-contracts v1.10.0 MIT
symfony/filesystem v4.4.42 MIT
symfony/http-client v5.4.38 MIT
symfony/http-client v5.4.39 MIT
symfony/http-client-contracts v2.5.3 MIT
symfony/panther v1.1.1 MIT
symfony/polyfill-ctype v1.29.0 MIT
symfony/polyfill-mbstring v1.29.0 MIT
symfony/polyfill-php80 v1.29.0 MIT
symfony/process v5.4.36 MIT
symfony/process v5.4.39 MIT
symfony/service-contracts v2.5.3 MIT
symfony/translation v4.4.47 MIT
symfony/translation-contracts v2.5.3 MIT
Expand Down
24 changes: 24 additions & 0 deletions src/ServiceContainer/Driver/PantherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Robertfausk\Behat\PantherExtension\ServiceContainer\Driver;

use Behat\MinkExtension\ServiceContainer\Driver\DriverFactory;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Robertfausk\Behat\PantherExtension\ServiceContainer\PantherConfiguration;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\Definition;
Expand Down Expand Up @@ -51,6 +52,29 @@ public function buildDriver(array $config)
);
}

// php-webdriver expects ChromeOptions instead of array since v1.15.0
// see: https://github.com/robertfausk/behat-panther-extension/issues/16
if (isset($config['manager_options']['capabilities'][ChromeOptions::CAPABILITY]) && 'goog:chromeOptions' === ChromeOptions::CAPABILITY) {
$chromeOptions = new ChromeOptions();
foreach ($config['manager_options']['capabilities'][ChromeOptions::CAPABILITY] as $name => $value) {
switch ($name) {
case 'prefs':
$chromeOptions->setExperimentalOption($name, $value);
break;
case 'args':
$chromeOptions->addArguments($value);
break;
case 'extensions':
$chromeOptions->addExtensions($value);
break;
case 'binary':
$chromeOptions->setBinary($value);
break;
}
}
$config['manager_options']['capabilities'][ChromeOptions::CAPABILITY] = $chromeOptions;
}

return new Definition(
'Behat\Mink\Driver\PantherDriver',
array(
Expand Down
46 changes: 46 additions & 0 deletions tests/Unit/Driver/PantherFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Tests\Unit\Driver;

use Facebook\WebDriver\Chrome\ChromeOptions;
use PHPUnit\Framework\TestCase;
use Robertfausk\Behat\PantherExtension\ServiceContainer\Driver\PantherFactory;

Expand Down Expand Up @@ -72,4 +73,49 @@ public function test_build_driver_without_options(): void
$this->assertArrayHasKey(0, $arguments, 'Arguments of definition should not be empty.');
$this->assertSame([], $arguments[0]);
}

public function test_build_chrome_driver_with_chrome_options_as_object_instead_of_array(): void
{
$config = [
'manager_options' => [
'connection_timeout_in_ms' => '5000',
'request_timeout_in_ms' => '120000',
'capabilities' => [
'goog:chromeOptions' => [
'prefs' => [
'download.default_directory' => '/var/www/html/tests/files/Downloads',
],
'args' => ['start-maximized'],
'binary' => ['/path/to/acme'],
'extensions' => ['/var/www/html/tests/fixtures/extension_dummy.ext'],
],
],
],
];
$pantherFactory = new PantherFactory();
$definition = $pantherFactory->buildDriver($config);
$arguments = $definition->getArguments();

$this->assertArrayHasKey(2, $arguments, 'Arguments of definition should not be empty.');
$this->assertArrayHasKey('connection_timeout_in_ms', $arguments[2]);
$this->assertSame('5000', $arguments[2]['connection_timeout_in_ms']);
$this->assertArrayHasKey('request_timeout_in_ms', $arguments[2]);
$this->assertSame('120000', $arguments[2]['request_timeout_in_ms']);
$this->assertArrayHasKey('capabilities', $arguments[2]);
$this->assertArrayHasKey('goog:chromeOptions', $arguments[2]['capabilities']);
$chromeOptions = $arguments[2]['capabilities']['goog:chromeOptions'];

if ('goog:chromeOptions' === ChromeOptions::CAPABILITY) {
$this->assertInstanceOf(ChromeOptions::class, $chromeOptions);
$chromeOptions = $chromeOptions->toArray();
// base64 encoded value of extension file content
$this->assertSame(['MTIzNDU2Nzg5MA=='], $chromeOptions['extensions']);
} else {
$this->assertSame(['/var/www/html/tests/fixtures/extension_dummy.ext'], $chromeOptions['extensions']);
}

$this->assertSame(['download.default_directory' => '/var/www/html/tests/files/Downloads'], $chromeOptions['prefs']);
$this->assertSame(['start-maximized'], $chromeOptions['args']);
$this->assertSame(['/path/to/acme'], $chromeOptions['binary']);
}
}
1 change: 1 addition & 0 deletions tests/fixtures/extension_dummy.ext
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1234567890

0 comments on commit 402b413

Please sign in to comment.