0
0
Selenium Javatesting~10 mins

Window management (maximize, size) in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a browser window, maximizes it, and then verifies that the window size is larger than a predefined minimum size.

Test Code - JUnit with Selenium WebDriver
Selenium Java
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();
        }
    }
}
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test starts and ChromeDriver is initializedBrowser is launched but no page loaded yet-PASS
2Browser navigates to https://example.comBrowser displays the example.com homepage-PASS
3Browser window is maximized using driver.manage().window().maximize()Browser window is maximized to full screen-PASS
4Retrieve current window size with driver.manage().window().getSize()Window size object with width and height is obtained-PASS
5Assert window width is at least 1024 pixelsWindow width value is checkedassertTrue(width >= 1024)PASS
6Assert window height is at least 768 pixelsWindow height value is checkedassertTrue(height >= 768)PASS
7Test ends and browser is closed with driver.quit()Browser is closed and WebDriver session ends-PASS
Failure Scenario
Failing Condition: Window size after maximize is smaller than expected minimum (width < 1024 or height < 768)
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after maximizing the browser window?
AThat the window title contains 'example.com'
BThat the page URL is correct
CThat the window size is at least 1024x768 pixels
DThat the browser is in fullscreen mode
Key Result
Always verify window size after maximizing to ensure your tests run in the expected viewport, as maximize behavior can vary by OS and browser.