Skip to content

Commit

Permalink
Fix and streamline capability handling
Browse files Browse the repository at this point in the history
  • Loading branch information
uuf6429 committed Nov 19, 2024
1 parent ca55cde commit f7093bb
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions src/WebdriverClassicDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,29 +789,22 @@ private function getNormalisedBrowserName(): string
*/
private function initCapabilities(array $desiredCapabilities): DesiredCapabilities
{
// Build base capabilities
$caps = $this->getBrowserSpecificCapabilities() ?? new DesiredCapabilities();

// Set defaults
$defaults = array_merge(
self::DEFAULT_CAPABILITIES['default'],
self::DEFAULT_CAPABILITIES[$this->getNormalisedBrowserName()] ?? []
);
foreach ($defaults as $key => $value) {
if ($caps->getCapability($key) === null) {
$caps->setCapability($key, $value);
}
}

// Merge in other requested types
foreach ($desiredCapabilities as $key => $value) {
$caps->setCapability($key, $value);
$capabilities = $this->createBrowserSpecificCapabilities();

foreach (
array_merge(
self::DEFAULT_CAPABILITIES['default'],
self::DEFAULT_CAPABILITIES[$this->getNormalisedBrowserName()] ?? [],
$desiredCapabilities,
) as $capabilityKey => $capabilityValue
) {
$capabilities->setCapability($capabilityKey, $capabilityValue);
}

return $caps;
return $capabilities;
}

private function getBrowserSpecificCapabilities(): ?DesiredCapabilities
private function createBrowserSpecificCapabilities(): DesiredCapabilities
{
switch ($this->getNormalisedBrowserName()) {
case WebDriverBrowserType::FIREFOX:
Expand Down Expand Up @@ -855,7 +848,7 @@ private function getBrowserSpecificCapabilities(): ?DesiredCapabilities
case WebDriverBrowserType::MOCK:
case WebDriverBrowserType::IE_HTA:
default:
return null;
return new DesiredCapabilities();
}
}

Expand Down

0 comments on commit f7093bb

Please sign in to comment.