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 |