Skip to content

Compatibility with ChromeDriver 2.31 #551

Closed

Description

@freiondrej

What are you trying to achieve? (Expected behavior)

setting chromeOptions

What do you get instead? (Actual behavior)

the options are ignored

How could the issue be reproduced? (Steps to reproduce)

With ChromeDriver 2.31, the option chromeOptions was renamed to goog:chromeOptions.

My code snippet started working as soon as I changed value of the constant Facebook\WebDriver\Chrome\ChromeOptions::CAPABILITY to 'goog:chromeOptions'.

Details

  • Php-webdriver version: 1.5.0
  • PHP version: 7.1.10
  • Selenium server version: 3.8.1
  • Operating system: Linux x86_64
  • Browser used + version: Chrome 65

Activity

  1. maidmaid commented on Aug 31, 2018

    @maidmaid

    A workaround could be to use ChromeOptions::setExperimentalOption():

    $perfLoggingPrefs = new \stdClass();
    $perfLoggingPrefs->enableNetwork = true;
    
    $chromeOptions = new ChromeOptions();
    $chromeOptions->setExperimentalOption('perfLoggingPrefs', $perfLoggingPrefs);
    
    $capabilities = DesiredCapabilities::chrome();
    $capabilities->setCapability(ChromeOptions::CAPABILITY, $chromeOptions);
  2. maidmaid commented on Aug 31, 2018

    @maidmaid

    Extra note following my previous comment : if your goal is to enable the performance log, you need this extra instructions :

    $loggingPrefs = new \stdClass();
    $loggingPrefs->performance = 'ALL';
    $capabilities->setCapability('loggingPrefs', $loggingPrefs);

    And then, for getting the logs :

    $webDriver()->manage()->getLog('performance');
    
  3. dotnetCarpenter commented on Dec 11, 2018

    @dotnetCarpenter

    @maidmaid Seems like a small error somehow in your code.

    ERROR: Facebook\WebDriver\Exception\ExpectedException: invalid argument: perfLoggingPrefs specified, but performance logging was not enabled

    $perfLoggingPrefs = new \stdClass();
    $perfLoggingPrefs->enableNetwork = true;
    
    $chromeOptions = new ChromeOptions();
    $chromeOptions->setExperimentalOption('perfLoggingPrefs', $perfLoggingPrefs);
    $chromeOptions->addArguments(['--headless', '--no-sandbox', '--disable-gpu']);
    
    $capabilities = DesiredCapabilities::chrome();
    $capabilities->setCapability(ChromeOptions::CAPABILITY, $chromeOptions);
    $capabilities->setCapability('logginPrefs', [
        'performance' => 'ALL',
        'browser' => 'ALL'
    ]);
    
    return RemoteWebDriver::create(
        'http://localhost:9515',
        $capabilities
    );

    ERROR: Facebook\WebDriver\Exception\ExpectedException: invalid argument: cannot parse capability: chromeOptions
    from invalid argument: cannot parse perfLoggingPrefs
    from invalid argument: unrecognized performance logging option: performance

    $perfLoggingPrefs = new \stdClass();
    $perfLoggingPrefs->enableNetwork = true;
    $perfLoggingPrefs->performance = 'ALL';
    
    $chromeOptions = new ChromeOptions();
    $chromeOptions->setExperimentalOption('perfLoggingPrefs', $perfLoggingPrefs);
    $chromeOptions->addArguments(['--headless', '--no-sandbox', '--disable-gpu']);
    
    $capabilities = DesiredCapabilities::chrome();
    $capabilities->setCapability(ChromeOptions::CAPABILITY, $chromeOptions);
    $capabilities->setCapability('logginPrefs', [
        'browser' => 'ALL'
    ]);
    
    return RemoteWebDriver::create(
        'http://localhost:9515',
        $capabilities
    );
  4. dotnetCarpenter commented on Dec 11, 2018

    @dotnetCarpenter

    @maidmaid Could you please write the whole snippet or link to the source code that specify the required arguments and types?

  5. maidmaid commented on Dec 16, 2018

    @maidmaid

    My complete snippet is :

    $capabilities = DesiredCapabilities::chrome();
    
    $chromeOptions = new ChromeOptions();
    $chromeOptions->addArguments($arguments);
    
    $perfLoggingPrefs = new \stdClass();
    $perfLoggingPrefs->enableNetwork = true;
    $chromeOptions->setExperimentalOption('perfLoggingPrefs', $perfLoggingPrefs);
    
    $loggingPrefs = new \stdClass();
    $loggingPrefs->performance = 'ALL';
    $capabilities->setCapability('loggingPrefs', $loggingPrefs);
    
    $capabilities->setCapability(ChromeOptions::CAPABILITY, $chromeOptions);
    
    RemoteWebDriver::create($url, $capabilities);

    Does it work it now ?

  6. dotnetCarpenter commented on Dec 17, 2018

    @dotnetCarpenter

    Thanks @maidmaid! I'll try tomorrow. If $arguments equals something similar to ['--headless', '--no-sandbox', '--disable-gpu'], then it looks straight forward.

  7. dotnetCarpenter commented on Dec 20, 2018

    @dotnetCarpenter

    @maidmaid Thx! It works beautifully :)

  8. edenreich commented on Jan 13, 2019

    @edenreich

    Thanks to @maidmaid , I organized the walkaround a bit, so if someone face this issue until const will be renamed / added, if at all.

            $options = new ChromeOptions;
            $capabilities = DesiredCapabilities::chrome();
            $host = 'http://selenium-hub:4444/wd/hub';
            $arguments = [
                // just as an example, this arguments are not required
                '--disable-gpu',
                '--headless',
                '--no-sandbox',
            ];
    
            $options->addArguments($arguments);
            $capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
    
            // this are the lines of code you need to add
            $object = new \stdClass;
            $object->args = $arguments;
            $capabilities->setCapability('goog:chromeOptions', $object);
    

    That way you set both chromeOptions and goog:chromeOptions(the new name).

  9. laurinkeithdavis commented on Jan 14, 2019

    @laurinkeithdavis

    Not trying to confuse the issue, but doing it this way works fine for us:

    $capabilities = new DesiredCapabilities();
    $options      = new ChromeOptions();
    
    $options->addArguments(
    	[
    		"window-size=1400,900",
    		"no-sandbox",
    		"headless"
    	]);
    $capabilities->setCapability(
    	ChromeOptions::CAPABILITY,
    	$options);
    
    $driver =
    	RemoteWebDriver::create(
    		"http://localhost:4444/wd/hub",
    		$capabilities);

    Since I'm fairly new to Selenium, I'm just curious as to why this works for us and not those posting in this issue? I verified, \Facebook\WebDriver\Chrome\ChromeOptions::CAPABILITY = 'chromeOptions'. So how does that work if ChromeDriver expects 'goog:chromeOptions'?

    Php-webdriver version: 1.6.0
    PHP version: 7.2.14
    Selenium server version: 3.14.0
    Selenium Chrome Driver: 2.45
    Operating system: Windows 10 x64
    Browser used + version: Chrome 71

  10. dotnetCarpenter commented on Jan 14, 2019

    @dotnetCarpenter

    @laurin1 Define works for us. Are you able to get the network requests?

    $webDriver()->manage()->getLog('performance');

    If not, then it does not work for you. This issue is about setting Chrome options in order get access to the various non-defaults. The only specific case, that is mentioned here, is the network requests under the performance log.

  11. laurinkeithdavis commented on Jan 14, 2019

    @laurinkeithdavis

    Again, I'm new here, so please go easy on me. The original issue says expected behavior is:

    setting chromeOptions

    With the actual behavior is:

    the options are ignored

    I can set these chrome options:

    			"window-size=1400,900",
    			"no-sandbox",
    			"headless"
    

    and verify they are working (well, not sure about the non-sandbox, but I've verified that the other 2 are working.

    But you are saying that this issue does not apply to the options I am referring to, correct?

  12. dotnetCarpenter commented on Jan 14, 2019

    @dotnetCarpenter

    But you are saying that this issue does not apply to the options I am referring to, correct?

    yes.

    Sorry if it sounded harsh. The description might be a little misleading. Then main issue is that ChromeDriver has different options settings depending on version as noted in the first comment.

    For the normal options this is not an issue since php-webdriver takes care of that for us.

    $capabilities = new DesiredCapabilities();
    $options       = new ChromeOptions();
    $options->addArguments(["window-size=1400,900", "no-sandbox", "headless"]);
    $capabilities->setCapability(ChromeOptions::CAPABILITY, $options);

    the above always works

    However, if you want to set other options, like getting console.log or network requests, php-webdriver does not help you and you need to know what ChromeDriver expects (depending on version).

    Hence:

    chromeOptions = (new ChromeOptions)->addArguments([
        '--disable-gpu',
        '--headless',
        '--no-sandbox'
    ]);
    
    // NETWORK LOGGING
    // https://github.com/facebook/php-webdriver/issues/551#issuecomment-447664692
    // https://github.com/beyondcode/dusk-dashboard/blob/master/src/Testing/TestCase.php#L54
    $perfLoggingPrefs = new \stdClass();
    $perfLoggingPrefs->enableNetwork = true;
    $chromeOptions->setExperimentalOption('perfLoggingPrefs', $perfLoggingPrefs);
    
    $capabilities = DesiredCapabilities::chrome()->setCapability(
        ChromeOptions::CAPABILITY, $chromeOptions
    );
    // see https://github.com/facebook/php-webdriver/issues/594#issuecomment-441037356
    $capabilities->setCapability('loggingPrefs', ['browser' => 'ALL', 'performance' => 'ALL']);
    
    return RemoteWebDriver::create(
        'http://localhost:9515',
        $capabilities
    );

    the above will give you access to getLog("browser") and getLog("performance")

    getLog("browser") is discussed in #594

  13. laurinkeithdavis commented on Jan 14, 2019

    @laurinkeithdavis

    Thanks for the detailed explanation. I'm having various issues right now and just trying to understand the various pieces to see what I am missing (and since my results did not match up what I though this issue was explaining, I was even more confused).

  14. edenreich commented on Jan 14, 2019

    @edenreich

    @dotnetCarpenter just wanted to point out, I still think it's an issue, and we should make it clear it's all because of the new versions of ChromeDriver that expect goog:chromeOptions in the args list that is sent with curl over HTTP on Remote/HttpCommandExecutor.php therefore, if you decide to set the capability differently (for example as the newer versions of ChromeDriver expecting them $capabilities->setCapability('goog:chromeOptions', $options) the arguments will be ignored.

        $capabilities = new DesiredCapabilities();
        $options       = new ChromeOptions();
        $options->addArguments(["window-size=1400,900", "no-sandbox", "headless"]);
        $capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
    

    So as you said, the above works... depending on the version

  15. OndraM commented on Nov 11, 2019

    @OndraM
    Collaborator

    This should be resolved by #673 and fixed in next php-webdriver release.

  16. ingowinkt commented on Feb 18, 2025

    @ingowinkt

    for me this worked:

    .setCapability("goog:loggingPrefs", logPrefs);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions