Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Condition prevents setting default capabilities #46

Open
uuf6429 opened this issue Nov 9, 2024 · 2 comments · May be fixed by #51
Open

Condition prevents setting default capabilities #46

uuf6429 opened this issue Nov 9, 2024 · 2 comments · May be fixed by #51
Labels
bug Something isn't working

Comments

@uuf6429
Copy link
Member

uuf6429 commented Nov 9, 2024

if ($caps->getCapability($key) === null) {

☝️ That condition means that we cannot overwrite capabilities by the php-webdriver - in case of Firefox, because of this:
https://github.com/php-webdriver/php-webdriver/blob/4c18b78d93e4a724ad2dd6427ed658e61a45c569/lib/Remote/DesiredCapabilities.php#L299

For example, the following firefox capability change would not work:

    public const DEFAULT_CAPABILITIES = [
        'default' => [
            'platform' => 'ANY',
            'name' => 'Behat Test',
            'deviceOrientation' => 'landscape',
            'deviceType' => 'desktop',
        ],

        WebDriverBrowserType::FIREFOX => [  // <<<<<<<
            'moz:firefoxOptions' => [
                'args' => [
                    'some-argument',
                ],
            ],
        ],
    ];

(that also applies to the default one; we're not able to overwrite anything predefined in the php-webdriver defaults)

I think this code was copied from MinkSelenium2Driver, so I never really thought about it.

On a related note, I'm unsure how in general we are supposed to behave - should we be merging config, or generally overwriting it? That applies to php-webdriver defaults, our defaults and the end user's desired capaibilities.

@aik099
Copy link
Member

aik099 commented Nov 9, 2024

The MinkSeleniumDriver does this:

// Join $desiredCapabilities with defaultCapabilities
$desiredCapabilities = array_replace(self::getDefaultCapabilities(), $desiredCapabilities);

The self::getDefaultCapabilities() method returns:

array(
    'browserName'       => 'firefox',
    'name'              => 'Behat Test',
);

So it's the array_replace function logic, that decides what will happen. PHP documentation says, that it's non-recursive.

This way you can only fully override a particular capability. In case of moz:firefoxOptions this means:

  • if user provides this array, then we'll use only what he has provided
  • if user doesn't prove this array, then we'll use our default full version of that array.

No nested merging.

@uuf6429 , Would such behavior cause any issues?

@aik099
Copy link
Member

aik099 commented Nov 9, 2024

Ah, in WebdriverClassicDriver (this repo) you're doing different kind of merging. Anyway, we need to have a test to cover the correct default merging logic in either driver I guess.

@uuf6429 uuf6429 added the bug Something isn't working label Nov 12, 2024
@uuf6429 uuf6429 linked a pull request Nov 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants