3

I'm trying to create node with following configurations:

java -Dwebdriver.chrome.driver=/randomfolder/chromedriver -jar selenium-server-standalone-3.4.0.jar -role node -nodeConfig node-conf.json

As you see I'm passing config in a json file. It sets the configurations correctly, except the chromeOptions. I need chrome to be opened headless. This is a part of my .json file, which sets the capabilities.

"capabilities": [
    {  
         "browserName":"chrome",
         "maxInstances":3,
         "version":"ServerLinux",
         "platform":"LINUX",
         "chromeOptions": {
            "args": ["--headless", "--disable-gpu" , "--window-size=1920x1080", "--no-sandbox"]
         }
     }
   ]

I've tried different ways of writing the chromeOptions, but node keeps constantly ignoring them. Am I just blind and don't see my mistake? Thanks in advance!

2 Answers2

0

I am also facing this issue, but in my case, I want to modify the user agent, and on Linux, chromeOptions just seems to be ignored. This is working for me locally on Mac/Chrome.

//wdio.conf.js
capabilities: [{
    browserName: "chrome",
    chromeOptions : {
        args : ['--user-agent=THIS_IS_A_TEST']
    }
  }],

//Jenkins job on Linux RHEA
13:42:33 [11/10/2018 13:42:33.049] [LOG]   browser.desiredCapabilities = {
13:42:33   "javascriptEnabled": true,
13:42:33   "locationContextEnabled": true,
13:42:33   "handlesAlerts": true,
13:42:33   "rotatable": true,
13:42:33   "browserName": "chrome",
13:42:33   "acceptInsecureCerts": true,
13:42:33   "chromeOptions": {
13:42:33     "args": [
13:42:33       "--user-agent=THIS_IS_A_TEST",
13:42:33       "window-size=1600,1200"
13:42:33     ]
13:42:33   },
13:42:33   "loggingPrefs": {
13:42:33     "browser": "ALL",
13:42:33     "driver": "ALL"
13:42:33   }
13:42:33 }
13:42:33 [11/10/2018 13:42:33.072] [LOG]   printNavigatorUserAgent() navigator.userAgent = Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36

Expected: printNavigatorUserAgent() navigator.userAgent = THIS_IS_A_TEST

printNavigatorUserAgent(){

  let result = browser.execute(function() {
      return navigator.userAgent;
  },);

  console.log(`printNavigatorUserAgent() navigator.userAgent = ${result.value}`);

}

Update: The following syntax is currently working for me on Linux/chrome.

//wdio.conf.js
capabilities: [{
  browserName: "chrome",
    "goog:chromeOptions" : {
      "args" : ['user-agent=THIS_IS_A_TEST']
  }
}],
Aaron
  • 1,024
  • 11
  • 11
0

A "try and guess" for the right JSON syntax is time consuming, and the schema might change anyway. The safest option is to pick the API for your language of choice, then assemble and generate the JSON yourself. Make sure to pick the version matching the Selenium site and stack you are targeting.

Example with Python:

from selenium.webdriver.chrome.options import Options as ChromeOptions

options = ChromeOptions()
options.add_argument('--incognito')
options.to_capabilities()

and that will look like:

{
 'browserName': 'chrome',
 'version': '',
 'platform': 'ANY',
 'goog:chromeOptions': {
   'extensions': [],
   'args': ['--incognito']
 }
}

As a final note, if your site is bringing in a capabilities list of its own, this override and that one might get merged, so bring in your deltas only to avoid surprises.

reim
  • 492
  • 5
  • 8