Maximize browser window

0 votes

Some websites implemented responsive design. So, the website looks differently on smaller screens.
Therefore it’s important to maximize the browser window before the test starts.

@Test
public void maximizeFirefox() {
  // Start browser
  System.setProperty("webdriver.gecko.driver", FileUtil.findFileOnPath("mac/geckodriver"));
  final FirefoxDriver driver = new FirefoxDriver();

  // Maximize browser
  driver.manage().window().maximize();

  // Open website
  driver.get("http://www.selenium-in-action.io");
}

There are several bug reports noticing that this feature doesn’t work when using ChromeDriver.
Luckily the is a workaround, we can start Chrome in kiosk mode (full screen without toolbars).

@Test
public void startChromeFullscreen() {
  // Start browser with specific options
  final ChromeOptions options = new ChromeOptions();
  options.addArguments("start-fullscreen");
  System.setProperty("webdriver.chrome.driver", FileUtil.findFileOnPath("mac/chromedriver"));
  final ChromeDriver driver = new ChromeDriver(options);

  // Open website 
  driver.get("http://www.selenium-in-action.io");
}

Kiosk mode

@Test
public void startChromeKioskMode() {
  // Start browser with specific options  
  final ChromeOptions options = new ChromeOptions();
  options.addArguments("--kiosk");
  System.setProperty("webdriver.chrome.driver", FileUtil.findFileOnPath("mac/chromedriver"));
  final ChromeDriver driver = new ChromeDriver(options);

  // Open website 
  driver.get("http://www.selenium-in-action.io");
}
Please follow and like us:
Follow by Email
Facebook
Google+
http://www.seleniuminaction.com/maximize-browser-window/
Twitter
LinkedIn
Resize browser window

Leave a Reply

Your email address will not be published. Required fields are marked *