我正在尝试创建具有以下配置的节点:

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

如您所见,我正在一个json文件中传递config。它可以正确设置配置,除了色度选项。我需要铬打开无头。这是我的.json文件的一部分,用于设置功能。
"capabilities": [
    {
         "browserName":"chrome",
         "maxInstances":3,
         "version":"ServerLinux",
         "platform":"LINUX",
         "chromeOptions": {
            "args": ["--headless", "--disable-gpu" , "--window-size=1920x1080", "--no-sandbox"]
         }
     }
   ]

我尝试过不同的方法来编写chromeoptions,但是node总是忽略它们。我只是瞎了眼,看不到我的错误吗?
提前谢谢!

最佳答案

我也面临这个问题,但在我的例子中,我想修改用户代理,而在linux上,chromeoptions似乎被忽略了。这在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

需要:printNavigatorUserAgent()navigator.userAgent=此测试
printNavigatorUserAgent(){

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

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

}

更新:以下语法目前适用于linux/chrome。
//wdio.conf.js
capabilities: [{
  browserName: "chrome",
    "goog:chromeOptions" : {
      "args" : ['user-agent=THIS_IS_A_TEST']
  }
}],

10-04 15:53