From be813657d1ca629017795be4634f5039df505f7a Mon Sep 17 00:00:00 2001 From: Ghostff Date: Fri, 19 May 2023 01:24:15 -0500 Subject: [PATCH 1/3] kill session --- src/FacebookWebDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FacebookWebDriver.php b/src/FacebookWebDriver.php index b8b93180..dfb03146 100755 --- a/src/FacebookWebDriver.php +++ b/src/FacebookWebDriver.php @@ -441,7 +441,7 @@ public function stop() $this->started = false; try { - $this->webDriver->close(); + $this->webDriver->quit(); } catch (Exception $e) { throw new DriverException('Could not close connection', 0, $e); } From d4ef525052cd6efc736a57cc6829677401d08a87 Mon Sep 17 00:00:00 2001 From: Ghostff Date: Fri, 19 May 2023 01:25:46 -0500 Subject: [PATCH 2/3] Remove w3c override --- src/FacebookFactory.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/FacebookFactory.php b/src/FacebookFactory.php index d44c719d..90e88287 100644 --- a/src/FacebookFactory.php +++ b/src/FacebookFactory.php @@ -11,6 +11,7 @@ namespace SilverStripe\MinkFacebookWebDriver; use Behat\MinkExtension\ServiceContainer\Driver\Selenium2Factory; +use Facebook\WebDriver\Remote\WebDriverBrowserType; use Symfony\Component\DependencyInjection\Definition; /** @@ -38,13 +39,10 @@ public function buildDriver(array $config) $extraCapabilities = $config['capabilities']['extra_capabilities']; unset($config['capabilities']['extra_capabilities']); - // PATCH: Disable W3C mode in chromedriver until we have capacity to actively adopt it - $extraCapabilities['chromeOptions'] = array_merge( - isset($extraCapabilities['chromeOptions']) ? $extraCapabilities['chromeOptions'] : [], - ['w3c' => false] - ); - - $capabilities = array_replace($this->guessCapabilities() ?? [], $extraCapabilities, $config['capabilities']); + $capabilities = $config['capabilities'] + ($this->guessCapabilities() ?? []); + if ($config['browser'] === WebDriverBrowserType::CHROME) { + $capabilities['chromeOptions'] = $extraCapabilities['chromeOptions']; + } // Build driver definition return new Definition(FacebookWebDriver::class, [ From 4b1512774c96b3942c80aa7f25c6d428e77f25a0 Mon Sep 17 00:00:00 2001 From: Ghostff Date: Fri, 19 May 2023 02:09:12 -0500 Subject: [PATCH 3/3] remove w3c override and kill driver session on stop --- .gitignore | 1 + README.md | 51 ++++++++++++++++------------ composer.json | 5 +-- src/BehatExtension/MinkExtension.php | 17 ++++++++++ 4 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 src/BehatExtension/MinkExtension.php diff --git a/.gitignore b/.gitignore index 1d034f43..4220d7ea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor composer.phar composer.lock phpunit.xml +.idea diff --git a/README.md b/README.md index 0d0fc1c9..d7317102 100644 --- a/README.md +++ b/README.md @@ -12,33 +12,18 @@ Major updates include: - Switch to using facebook/webdriver - Selenium optional, can use chromedriver (or other jsonwire protocol servers instead) - Default to `chrome` instead of `firefox` - - Update minimum php version to 5.6 + - Update minimum php version to 8.1 ## Using the Facebook WebDriver with behat -Subclass `Behat\MinkExtension\ServiceContainer\MinkExtension` and add the new driver factory. - -```php -registerDriverFactory(new FacebookFactory()); - } -} +Install package +```shell +composer require silverstripe/mink-facebook-web-driver --dev ``` Add this extension to your `behat.yml` (see below) -## Running chromedriver instead of selenium +## Running chromedriver Make sure you install chromedriver and have the service running @@ -52,7 +37,7 @@ Only local connections are allowed. Set the wb_host to this server instead (substitute `SilverStripe\BehatExtension\MinkExtension` for your class). -``` +```yaml default: suites: [] extensions: @@ -64,6 +49,30 @@ default: wd_host: "http://127.0.0.1:9515" #chromedriver port ``` +## Running Selenium +Yml configuration for Docker `selenium/hub:4.9.1` and `selenium/node-chrome:113.0` +```yaml +default: + extensions: + SilverStripe\BehatExtension\MinkExtension: + base_url: http://localhost # required + default_session: facebook_web_driver + javascript_session: facebook_web_driver + facebook_web_driver: + browser: chrome + wd_host: "http://selenium-hub:4444/wd/hub" # or http://localhost:4444/wd/hub + capabilities: + browser: chrome + version: "113.0" + platform: linux + marionette: true + extra_capabilities: + chromeOptions: + w3c: true + args: [ '--no-sandbox' ] +``` + + ## Common problems * `System.InvalidOperationException : unknown error: call function result missing 'value'`: diff --git a/composer.json b/composer.json index fd405fb6..1db593dd 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "require": { "php": "^8.1", "behat/mink": "^1.10.0", - "php-webdriver/webdriver": "^1.13.1" + "php-webdriver/webdriver": "^1.13.1", + "friends-of-behat/mink-extension": "^2.7" }, "require-dev": { "squizlabs/php_codesniffer": "^3.7" @@ -40,4 +41,4 @@ "SilverStripe\\MinkFacebookWebDriver\\": "src/" } } -} \ No newline at end of file +} diff --git a/src/BehatExtension/MinkExtension.php b/src/BehatExtension/MinkExtension.php new file mode 100644 index 00000000..bcc209f8 --- /dev/null +++ b/src/BehatExtension/MinkExtension.php @@ -0,0 +1,17 @@ +registerDriverFactory(new FacebookFactory()); + } +}