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

Remove w3c override and kill driver session on stop #25

Open
wants to merge 3 commits into
base: 2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor
composer.phar
composer.lock
phpunit.xml
.idea
51 changes: 30 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php

namespace SilverStripe\BehatExtension;

use Behat\MinkExtension\ServiceContainer\MinkExtension as BaseMinkExtension;
use SilverStripe\MinkFacebookWebDriver\FacebookFactory;

class MinkExtension extends BaseMinkExtension
{
public function __construct()
{
parent::__construct();
$this->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

Expand All @@ -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:
Expand All @@ -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'`:
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -40,4 +41,4 @@
"SilverStripe\\MinkFacebookWebDriver\\": "src/"
}
}
}
}
17 changes: 17 additions & 0 deletions src/BehatExtension/MinkExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace SilverStripe\MinkFacebookWebDriver\BehatExtension;

use Behat\MinkExtension\ServiceContainer\MinkExtension as BaseMinkExtension;
use SilverStripe\MinkFacebookWebDriver\FacebookFactory;

class MinkExtension extends BaseMinkExtension
{
public function __construct()
{
parent::__construct();
$this->registerDriverFactory(new FacebookFactory());
}
}
12 changes: 5 additions & 7 deletions src/FacebookFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace SilverStripe\MinkFacebookWebDriver;

use Behat\MinkExtension\ServiceContainer\Driver\Selenium2Factory;
use Facebook\WebDriver\Remote\WebDriverBrowserType;
use Symfony\Component\DependencyInjection\Definition;

/**
Expand Down Expand Up @@ -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, [
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down