1

I would like to know how can I maximize the browser window using Selenium Grid and RemoteWebDriver with the most popular browsers.

This question has not been solved yet in this community, there is another question that could look like this: How do I maximize the browser window in Selenium WebDriver (Selenium 2) using C#? But in that question is not clear how to maximize the browser window in RemoteWebDriver.

On Firefox and IE I guess it is in the same way driver.manage().window().maximize();

In Chrome we have to do:

ChromeOptions options = new ChromeOptions(); options.AddArgument("--start-maximized"); driver = new ChromeDriver(options);

The question is how can I apply that to RemoteWebDriver?

Community
  • 1
  • 1
Lorenzo Lerate
  • 3,552
  • 3
  • 26
  • 25
  • Possible duplicate of [How do I maximize the browser window in Selenium WebDriver (Selenium 2) using C#?](http://stackoverflow.com/questions/3189430/how-do-i-maximize-the-browser-window-in-selenium-webdriver-selenium-2-using-c) – Florent B. Nov 17 '16 at 14:52
  • 1
    I do not think so. In this case the question is related to RemoteWebDriver. – Lorenzo Lerate Nov 17 '16 at 15:05
  • The `RemoteWebDriver` is the underlying instance of the `WebDriver`. They share more or less the same API. – Florent B. Nov 17 '16 at 15:15
  • 1
    We cannot do `driver.manage().window().maximize();` on Chrome – Lorenzo Lerate Nov 17 '16 at 15:39
  • @LorenzoLerate What do you mean, you cannot do? `RemoteWebDriver driver = new ChromeDriver(); driver.manage().window().maximize();` compiles fine. If it has no effect, follow the link to the other question. – Würgspaß Nov 17 '16 at 16:05
  • 1
    @Würgspaß in the link they say it only works on Firefox and IE. In Chrome we have to do `ChromeOptions options = new ChromeOptions(); options.AddArgument("--start-maximized"); driver = new ChromeDriver(options);` The question is how to apply that to RemoteWebDriver – Lorenzo Lerate Nov 17 '16 at 16:50

2 Answers2

3

If i understand your question correctly you want to know how to pass driver options to remote driver.In that case where ever you are creating driver object you need to create desire capabilities and use one of the constructor of the remote driver with capability parameter. For example

DesiredCapabilities capabilities = DesiredCapabilities.chrome();

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

capabilities.setCapability(ChromeOptions.CAPABILITY, options);

driver = new RemoteWebDriver(URL, capabilities);
//driver = new ChromeDriver(capabilities);

You also can use QAF which abstraction driver configuration and management outside the code. Where you can set driver capabilities by using properties. As alternate You also can use Driver listener for such purpose. For example:

Using Properties:

Following two properties will do the needful for chrome driver:

drive.name=chromeDriver
chrome.additional.capabilities={"chromeOptions":{"args":["--start-maximized"]}}

For remote driver:

remote.server=<remote server or grid url>
drive.name=chromeRemoteDriver
chrome.additional.capabilities={"chromeOptions":{"args":["--start-maximized"]}}

Using Listener:

void beforeInitialize(Capabilities capabilities){
    if(capabilities.getBrowserName().equalIgnorCase("chrome"){
        ChromeOptions options = new ChromeOptions(); 
        options.addArguments("--start-maximized"); 
        ((DesiredCapabilities)capabilities).setCapability(ChromeOptions.CAPABILITY, options);
    }
}

void onInitialize(QAFExtendedWebDriver driver){
   //for browser other than chrome...
   driver.manage().window().maximize();
}
user861594
  • 5,733
  • 3
  • 29
  • 45
0

In Java you could do it like this:

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

It was already hinted at in the comments but to point it out: You can assign a ChromeDriver instance to a RemoteWebDriver type.

Würgspaß
  • 4,660
  • 2
  • 25
  • 41