Skip to content

Commit 5848cdb

Browse files
committed
Do not fail in isDisplayed call when capabilities are missing in WebDriver (fixes php-webdriver#1022)
1 parent 83cefc5 commit 5848cdb

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
This project versioning adheres to [Semantic Versioning](http://semver.org/).
33

44
## Unreleased
5+
### Fixed
6+
- Do not fail when using `isDisplayed()` and capabilities are missing in WebDriver instance. (Happens when driver instance was created using `RemoteWebDriver::createBySessionID()`.)
57

68
## 1.13.0 - 2022-10-03
79
### Added

lib/Remote/RemoteWebDriver.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class RemoteWebDriver implements WebDriver, JavaScriptExecutor, WebDriverHasInpu
2424
*/
2525
protected $executor;
2626
/**
27-
* @var WebDriverCapabilities
27+
* @var WebDriverCapabilities|null
2828
*/
2929
protected $capabilities;
3030

@@ -544,7 +544,7 @@ public function getSessionID()
544544
/**
545545
* Get capabilities of the RemoteWebDriver.
546546
*
547-
* @return WebDriverCapabilities
547+
* @return WebDriverCapabilities|null
548548
*/
549549
public function getCapabilities()
550550
{
@@ -578,7 +578,13 @@ public function execute($command_name, $params = [])
578578
// As we so far only use atom for IS_ELEMENT_DISPLAYED, this condition is hardcoded here. In case more atoms
579579
// are used, this should be rewritten and separated from this class (e.g. to some abstract matcher logic).
580580
if ($command_name === DriverCommand::IS_ELEMENT_DISPLAYED
581-
&& IsElementDisplayedAtom::match($this->getCapabilities()->getBrowserName())) {
581+
&& (
582+
// When capabilities are missing in php-webdriver 1.13.x, always fallback to use the atom
583+
$this->getCapabilities() === null
584+
// If capabilities are present, use the atom only if condition matches
585+
|| IsElementDisplayedAtom::match($this->getCapabilities()->getBrowserName())
586+
)
587+
) {
582588
return (new IsElementDisplayedAtom($this))->execute($params);
583589
}
584590

0 commit comments

Comments
 (0)