11

I need chrome to start maximized when running via the selenium grid.

This is how do I initialize it now:

Selenium selenium = new DefaultSelenium("localhost", 4444, "*googlechrome", "http://www.google.com");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);

Chrome does come up, but not maximized. In usual ChromeDriver I did it like this

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");

But I dont know how to pass it to RemoteWebDriver. Can anybody help?

Pavel Janicek
  • 14,128
  • 14
  • 53
  • 77

3 Answers3

32
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);

That's how I do it.

Petr Janeček
  • 37,768
  • 12
  • 121
  • 145
  • The code above looks good, but when I tried it, I got "cannot parse capability: chromeOptions on the node." Is there something I am missing? – DoodleKana Feb 06 '15 at 17:36
  • Honestly, I don't know, sorry. I didn't observe the Webdriver development over the past two years too much. Try looking for a mention of this in the chsngelog, or post a new question. – Petr Janeček Feb 06 '15 at 17:41
  • I found out the answer to my question here https://code.google.com/p/selenium/issues/detail?id=7043 with new selenium update options is used slightly different. – DoodleKana Feb 06 '15 at 22:27
3

Ok, I found it, so lets answer my own question :)

Selenium selenium = new DefaultSelenium("localhost", 4444, "*googlechrome", "http://www.google.com");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);

should work :}

Pavel Janicek
  • 14,128
  • 14
  • 53
  • 77
  • 2
    I will accept your answer - to give you appreciation for the effort. Anyways "google before post" should be new "think before speak" - at least in my case ;) – Pavel Janicek Mar 30 '12 at 12:01
1

The above solutions did not work for me but this did

ChromeOptions options = new ChromeOptions();
options.AddArguments("--start-maximized");

DesiredCapabilities capabilities = options.ToCapabilities() as DesiredCapabilities;
capabilities?.SetCapability(CapabilityType.BrowserName, "chrome");

Driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities);

Hope this helps someone.

SRack
  • 11,495
  • 5
  • 47
  • 60
Brian Mitchell
  • 345
  • 3
  • 21