There are times when we want to to maximize the browser window during the execution of our script .For this purpose webdriver providers a built-in method and here is the syntax :
WebDriver driver; driver.manage().window().maximize();Here is the sample code using TestNG framework. :
import java.awt.Toolkit; import java.io.IOException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.Reporter; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class MaximizeWindow { WebDriver driver; @BeforeTest public void setUpDriver() { driver = new FirefoxDriver(); } @Test public void maximize() { //declare varibales for windows org.openqa.selenium.Dimension defaultDim; org.openqa.selenium.Dimension maximizeDim; //Load google website on browser driver.get("http://google.com"); //Display the current screen dimensions defaultDim=driver.manage().window().getSize(); System.out.println("screenHeight before maximizing"+defaultDim.getHeight()); System.out.println("screenWidth before maximizing"+defaultDim.getWidth()); //maximize the window using webdriver method driver.manage().window().maximize(); //Display the maximized window dimensions maximizeDim=driver.manage().window().getSize(); System.out.println("screenHeight after maximizing:"+maximizeDim.getHeight()); System.out.println("screenWidth after maximizing:"+maximizeDim.getWidth()); } }Last but not the least
Belated Happy New Year All..!!
Have fun..!! :)