Skip to content

Commit 4bfeba1

Browse files
committed
Inform developers about non-working "rightClick" on Selenium Server 3.x
1 parent bedccba commit 4bfeba1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Selenium2Driver.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class Selenium2Driver extends CoreDriver
6868
*/
6969
private $isW3C = false;
7070

71+
/**
72+
* @var bool
73+
*/
74+
private $isRightClickSupported = false;
75+
7176
/**
7277
* The timeout configuration
7378
* @var array{script?: int, implicit?: int, page?: int}
@@ -352,7 +357,11 @@ public function start()
352357
$this->wdSession = $this->webDriver->session($this->browserName, $this->desiredCapabilities);
353358

354359
$status = $this->webDriver->status();
355-
$this->isW3C = version_compare($status['build']['version'], '3.0.0', '>=');
360+
list($majorSeleniumServerVersion) = explode('.', $status['build']['version']);
361+
$this->isW3C = (int)$majorSeleniumServerVersion >= 3;
362+
363+
// See: https://github.com/SeleniumHQ/selenium/commit/085ceed1f55fbaaa1d419b19c73264415c394905.
364+
$this->isRightClickSupported = (int)$majorSeleniumServerVersion !== 3;
356365

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

937946
public function rightClick(string $xpath)
938947
{
948+
if (!$this->isRightClickSupported) {
949+
throw new DriverException(<<<TEXT
950+
The right-clicking functionality, via JsonWireProtocol, is not available on the Selenium Server 3.x.
951+
952+
Please use "mink/webdriver-classic-driver" Mink driver or downgrade to Selenium Server 2.x.
953+
TEXT
954+
);
955+
}
956+
939957
$this->mouseOver($xpath);
940958
$this->getWebDriverSession()->click(array('button' => 2));
941959
}

tests/Selenium2Config.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Behat\Mink\Tests\Driver\Basic\BasicAuthTest;
88
use Behat\Mink\Tests\Driver\Basic\HeaderTest;
99
use Behat\Mink\Tests\Driver\Basic\StatusCodeTest;
10+
use Behat\Mink\Tests\Driver\Css\HoverTest;
11+
use Behat\Mink\Tests\Driver\Js\EventsTest;
1012
use Behat\Mink\Tests\Driver\Js\JavascriptTest;
1113

1214
class Selenium2Config extends AbstractConfig
@@ -72,6 +74,16 @@ public function skipMessage($testCase, $test): ?string
7274
}
7375
}
7476

77+
if (array(HoverTest::class, 'testRightClickHover') === array($testCase, $test)
78+
|| array(EventsTest::class, 'testRightClick') === array($testCase, $test)
79+
) {
80+
list($majorSeleniumServerVersion) = explode('.', $_SERVER['SELENIUM_VERSION'] ?? '0.0.0');
81+
82+
if ((int)$majorSeleniumServerVersion === 3) {
83+
return 'The Selenium Server 3.x doesn\'t support right-clicking via JsonWireProtocol. See https://github.com/SeleniumHQ/selenium/commit/085ceed1f55fbaaa1d419b19c73264415c394905.';
84+
}
85+
}
86+
7587
return parent::skipMessage($testCase, $test);
7688
}
7789

0 commit comments

Comments
 (0)