Test Overview
This test opens a browser window, maximizes it, and then verifies that the window size is larger than a predefined minimum size.
This test opens a browser window, maximizes it, and then verifies that the window size is larger than a predefined minimum size.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.Dimension; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class WindowManagementTest { private WebDriver driver; @BeforeEach public void setUp() { driver = new ChromeDriver(); } @Test public void testWindowMaximizeAndSize() { driver.get("https://example.com"); driver.manage().window().maximize(); Dimension size = driver.manage().window().getSize(); int width = size.getWidth(); int height = size.getHeight(); assertTrue(width >= 1024, "Window width should be at least 1024 pixels"); assertTrue(height >= 768, "Window height should be at least 768 pixels"); } @AfterEach public void tearDown() { if (driver != null) { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and ChromeDriver is initialized | Browser is launched but no page loaded yet | — | PASS |
| 2 | Browser navigates to https://example.com | Browser displays the example.com homepage | — | PASS |
| 3 | Browser window is maximized using driver.manage().window().maximize() | Browser window is maximized to full screen | — | PASS |
| 4 | Retrieve current window size with driver.manage().window().getSize() | Window size object with width and height is obtained | — | PASS |
| 5 | Assert window width is at least 1024 pixels | Window width value is checked | assertTrue(width >= 1024) | PASS |
| 6 | Assert window height is at least 768 pixels | Window height value is checked | assertTrue(height >= 768) | PASS |
| 7 | Test ends and browser is closed with driver.quit() | Browser is closed and WebDriver session ends | — | PASS |
maximize() method do in Selenium WebDriver window management?maximize() method is used to enlarge the browser window to fill the entire screen.setSize() which sets a custom size, maximize() fills the screen automatically.setSize() requires a Dimension object with width and height.driver.manage().window().setSize(new Dimension(1024, 768));. Other options misuse method names or parameters.driver.manage().window().setSize(new Dimension(800, 600)); Dimension size = driver.manage().window().getSize(); System.out.println(size.getWidth() + "," + size.getHeight());
setSize().getSize() method returns the current size, which is then printed as "width,height".driver.manage().window().setSize(1024, 768);
setSize() method requires a single Dimension object, not two separate integers.maximize() without parameters to fill the screen.getSize() and compare width with 1200 pixels.Pass the test and this pattern moves unknown