Skip to content
20 changes: 19 additions & 1 deletion src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ class Selenium2Driver extends CoreDriver
*/
private $isW3C = false;

/**
* @var bool
*/
private $isRightClickSupported = false;

/**
* The timeout configuration
* @var array{script?: int, implicit?: int, page?: int}
Expand Down Expand Up @@ -352,7 +357,11 @@ public function start()
$this->wdSession = $this->webDriver->session($this->browserName, $this->desiredCapabilities);

$status = $this->webDriver->status();
$this->isW3C = version_compare($status['build']['version'], '3.0.0', '>=');
list($majorSeleniumServerVersion) = explode('.', $status['build']['version']);
Comment thread
aik099 marked this conversation as resolved.
Outdated
$this->isW3C = (int)$majorSeleniumServerVersion >= 3;

// See: https://github.com/SeleniumHQ/selenium/commit/085ceed1f55fbaaa1d419b19c73264415c394905.
$this->isRightClickSupported = (int)$majorSeleniumServerVersion !== 3;

$this->applyTimeouts();
$this->initialWindowHandle = $this->getWebDriverSession()->window_handle();
Expand Down Expand Up @@ -936,6 +945,15 @@ public function doubleClick(string $xpath)

public function rightClick(string $xpath)
{
if (!$this->isRightClickSupported) {
throw new DriverException(<<<TEXT
The right-clicking functionality, via JsonWireProtocol, is not available on the Selenium Server 3.x.
Comment thread
aik099 marked this conversation as resolved.
Outdated

Please use "mink/webdriver-classic-driver" Mink driver or downgrade to Selenium Server 2.x.
TEXT
);
}

$this->mouseOver($xpath);
$this->getWebDriverSession()->click(array('button' => 2));
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Selenium2Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Behat\Mink\Tests\Driver\Basic\BasicAuthTest;
use Behat\Mink\Tests\Driver\Basic\HeaderTest;
use Behat\Mink\Tests\Driver\Basic\StatusCodeTest;
use Behat\Mink\Tests\Driver\Css\HoverTest;
use Behat\Mink\Tests\Driver\Js\EventsTest;
use Behat\Mink\Tests\Driver\Js\JavascriptTest;

class Selenium2Config extends AbstractConfig
Expand Down Expand Up @@ -72,6 +74,16 @@ public function skipMessage($testCase, $test): ?string
}
}

if (array(HoverTest::class, 'testRightClickHover') === array($testCase, $test)
|| array(EventsTest::class, 'testRightClick') === array($testCase, $test)
) {
list($majorSeleniumServerVersion) = explode('.', $_SERVER['SELENIUM_VERSION'] ?? '0.0.0');
Comment thread
aik099 marked this conversation as resolved.
Outdated

if ((int)$majorSeleniumServerVersion === 3) {
return 'The Selenium Server 3.x doesn\'t support right-clicking via JsonWireProtocol. See https://github.com/SeleniumHQ/selenium/commit/085ceed1f55fbaaa1d419b19c73264415c394905.';
}
}

return parent::skipMessage($testCase, $test);
}

Expand Down