title: How to Merge Chrome driver service with desired capabilities for headless using xvfb?
body: <p>I want to merge <code>ChromeDriverService</code> with <code>chromeOptions</code> or with <code>DesiredCapabilities</code> for running browser in xvfb.</p>
  
  <p>Below is part of code <code>ChromeDriverService</code> I previously used without selenium grid.</p>
  
  <pre><code>String NodeChromeIncognito = "http://localhost:5558/wd/hub"
  
           ChromeDriverService chromeDriverService = new ChromeDriverService.Builder()
           .usingDriverExecutable(new File("driver_linux/chromedriver"))
           .usingAnyFreePort()
           .withEnvironment(ImmutableMap.of("DISPLAY", ":1")).build();
       chromeDriverService.start();
      // commented because using RemoteWebDriver
      // driver = new ChromeDriver(chromeDriverService);
  </code></pre>
  
  <p>and below is part code of RemoteWebDriver which I will merge with <code>ChromeDriverService</code>.</p>
  
  <pre><code>DesiredCapabilities cap = null;
  String NodeChromeIncognito = "http://localhost:5558/wd/hub";
  String NodeChrome = "http://localhost:5557/wd/hub";
  String NodeFirefox = "http://localhost:5556/wd/hub";
  
      if (browserName.equals("chrome")) {
          cap = DesiredCapabilities.chrome();
          cap.setBrowserName("chrome");
          driver = new RemoteWebDriver(new URL(NodeChrome), cap);
      } else if (browserName.equals("firefox")) {
          System.setProperty("webdriver.gecko.driver", "driver_linux/geckodriver");
          cap = DesiredCapabilities.firefox();
          cap.setCapability("marionette", true);
          driver = new RemoteWebDriver(new URL(NodeFirefox), cap);
      }else if (browserName.equals("chromeIncognito")) {
          ChromeOptions option = new ChromeOptions();
          option.addArguments("--incognito");
  
          cap = DesiredCapabilities.chrome();
          cap.setCapability(ChromeOptions.CAPABILITY, option);
          cap.setPlatform(Platform.WIN10);
          cap.setBrowserName("chrome incognito");
          driver = new RemoteWebDriver(new URL(NodeChromeIncognito), cap);
      }
  </code></pre>
  
  <p>I know I could use <code>addArguments("--headless")</code> for chrome, but it does not work well with the my webApp. And also I used <code>DesiredCapabilities.merge</code> and error.</p>
  
  <p>How to merge code/configuration <code>ChromeDriverService</code> with <code>ChromeOptions</code> or <code>DesiredCapabilites</code> ?</p>