Skip to content

Commit 65301ae

Browse files
committed
Block driver usage above Selenium Server 3.x
1 parent b493d5b commit 65301ae

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

src/Selenium2Driver.php

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

71-
/**
72-
* @var bool
73-
*/
74-
private $isRightClickSupported = false;
75-
7671
/**
7772
* The timeout configuration
7873
* @var array{script?: int, implicit?: int, page?: int}
@@ -354,12 +349,20 @@ private function executeJsOnElement(Element $element, string $script, bool $sync
354349
public function start()
355350
{
356351
try {
357-
$this->wdSession = $this->webDriver->session($this->browserName, $this->desiredCapabilities);
358-
359352
$status = $this->webDriver->status();
360353
$majorSeleniumServerVersion = (int)explode('.', $status['build']['version'])[0];
361-
$this->isW3C = $majorSeleniumServerVersion >= 3;
362-
$this->isRightClickSupported = $majorSeleniumServerVersion !== 3;
354+
355+
if ($majorSeleniumServerVersion > 3) {
356+
throw new \Exception(<<<TEXT
357+
The Selenium Server {$status['build']['version']} is not supported.
358+
359+
Please use the "mink/webdriver-classic-driver" Mink driver or switch to Selenium Server 2.x/3.x.
360+
TEXT
361+
);
362+
}
363+
364+
$this->isW3C = $majorSeleniumServerVersion === 3;
365+
$this->wdSession = $this->webDriver->session($this->browserName, $this->desiredCapabilities);
363366

364367
$this->applyTimeouts();
365368
$this->initialWindowHandle = $this->getWebDriverSession()->window_handle();
@@ -943,12 +946,12 @@ public function doubleClick(string $xpath)
943946

944947
public function rightClick(string $xpath)
945948
{
946-
if (!$this->isRightClickSupported) {
949+
if ($this->isW3C) {
947950
// See: https://github.com/SeleniumHQ/selenium/commit/085ceed1f55fbaaa1d419b19c73264415c394905.
948951
throw new DriverException(<<<TEXT
949-
Right-clicking via JsonWireProtocol is not possible on Selenium Server 3.
952+
Right-clicking via JsonWireProtocol is not possible on Selenium Server 3.x.
950953
951-
Please use the "mink/webdriver-classic-driver" Mink driver or switch to Selenium Server 2 or 4+.
954+
Please use the "mink/webdriver-classic-driver" Mink driver or switch to Selenium Server 2.x.
952955
TEXT
953956
);
954957
}

tests/Selenium2Config.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ public function skipMessage($testCase, $test): ?string
8080
$majorSeleniumServerVersion = (int)explode('.', $_SERVER['SELENIUM_VERSION'] ?? '0.0.0')[0];
8181

8282
if ($majorSeleniumServerVersion === 3) {
83-
return 'The Selenium Server 3.x doesn\'t support right-clicking via JsonWireProtocol. See https://github.com/SeleniumHQ/selenium/commit/085ceed1f55fbaaa1d419b19c73264415c394905.';
83+
return <<<TEXT
84+
The Selenium Server 3.x doesn't support right-clicking via JsonWireProtocol.
85+
86+
See https://github.com/SeleniumHQ/selenium/commit/085ceed1f55fbaaa1d419b19c73264415c394905.
87+
TEXT;
8488
}
8589
}
8690

0 commit comments

Comments
 (0)