robertfausk / behat-panther-extension

Run your behat tests in a headless chrome/firefox - Symfony Panther extension for Behat
https://packagist.org/packages/robertfausk/behat-panther-extension
Other
30 stars 5 forks source link

goog:chromeOptions throwing fatal error? #16

Closed validaide-mark-bijl closed 4 months ago

validaide-mark-bijl commented 4 months ago

Dear Robert,

First of all thank you for making this package! We are trying out this package as a replacement for our Selenium approach. Everything appeared to work fine as a drop-in replacement, until we attempted to configure the Chrome download directory to test for downloads.

When we configure the 'goog:chromeOptions' as described:

...
        javascript_chrome:
          panther:
            options:
              browser: 'chrome'
              webServerDir: '%paths.base%/public'
            manager_options:
              connection_timeout_in_ms: 5000
              request_timeout_in_ms: 120000
              chromedriver_arguments:
                - --window-size=1280,1600
                - --log-path=var/build/chromedriver.log
#                - --verbose
              capabilities:
                goog:chromeOptions:
                  prefs:
                    download.default_directory: 'var/build'
...

we get the following error:

Behat\Testwork\Call\Exception\FatalThrowableError: Fatal error: Call to a member function addArguments() on array in vendor/symfony/panther/src/ProcessManager/ChromeManager.php:68

Now either we're overlooking something in our YML file, or could it be that something is amiss in the processing of the 'goog:chromeOptions' part?

It seems here:

vendor/symfony/panther/src/ProcessManager/ChromeManager.php

...
 if ($this->arguments) {
            $chromeOptions = $capabilities->getCapability(ChromeOptions::CAPABILITY);
            if (null === $chromeOptions) {
                $chromeOptions = new ChromeOptions();
                $capabilities->setCapability(ChromeOptions::CAPABILITY, $chromeOptions);
            }
            $chromeOptions->addArguments($this->arguments);

            if (isset($_SERVER['PANTHER_CHROME_BINARY'])) {
                $chromeOptions->setBinary($_SERVER['PANTHER_CHROME_BINARY']);
            }
        }
...

That this statement $chromeOptions = $capabilities->getCapability(ChromeOptions::CAPABILITY); returns an array, and not a ChromeOptions object..?

Are we doing something wrong on our end, and if so, could you help us point out the mistake, or... is something not adding up?

Your help much appreciated! Thanks, Mark

robertfausk commented 4 months ago

Hi Mark,

at first: Thank you for trying out and your issue!

I ran into the same problem.

Besides symfony/panther it has also something to do by new release 1.15.0 of php-webdriver. I think this commit introduced a breaking change for us: https://github.com/php-webdriver/php-webdriver/commit/235c2aa07f9e2686f2b876083fc081b00d330d48 with this issue: https://github.com/php-webdriver/php-webdriver/pull/1063 See for full changelog: https://github.com/php-webdriver/php-webdriver/compare/1.14.0...1.15.0

My workaround for now is/was to pin php-webdriver to 1.14.0:

    ...
    "require-dev": {
        ...
        "php-webdriver/webdriver": "1.14.0",
        ...

Actually I am preparing a new release to support >=1.15.0 of php-webdriver.

robertfausk commented 4 months ago

Just released v1.1.3. @validaide-mark-bijl Pls reopen if you still encouter issues.