0
0
Selenium Javatesting~15 mins

EdgeOptions configuration in Selenium Java - Build an Automation Script

Choose your learning style9 modes available
Configure Microsoft Edge browser with EdgeOptions and verify browser launch
Preconditions (3)
Step 1: Create an EdgeOptions object
Step 2: Set the browser to start maximized using EdgeOptions
Step 3: Add an argument to disable browser notifications using EdgeOptions
Step 4: Initialize EdgeDriver with the configured EdgeOptions
Step 5: Navigate to https://www.example.com
Step 6: Verify that the browser window is maximized
Step 7: Verify that the page title contains 'Example Domain'
Step 8: Close the browser
✅ Expected Result: Microsoft Edge browser launches maximized without notifications, navigates to example.com, and page title contains 'Example Domain'. Browser closes successfully.
Automation Requirements - Selenium WebDriver with Java
Assertions Needed:
Assert that the browser window size matches the screen size (maximized)
Assert that the page title contains 'Example Domain'
Best Practices:
Use explicit waits if needed (though not mandatory here)
Use EdgeOptions to configure browser capabilities
Use try-finally or @After method to ensure browser closes
Use By locators only if interacting with page elements (not needed here)
Avoid hardcoded waits; prefer implicit or explicit waits
Automated Solution
Selenium Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.Dimension;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.awt.Toolkit;

public class EdgeOptionsTest {
    private WebDriver driver;

    @BeforeEach
    public void setUp() {
        // Create EdgeOptions object
        EdgeOptions options = new EdgeOptions();
        // Start browser maximized
        options.addArguments("--start-maximized");
        // Disable notifications
        options.addArguments("--disable-notifications");

        // Initialize EdgeDriver with options
        driver = new EdgeDriver(options);
    }

    @Test
    public void testEdgeOptionsConfiguration() {
        // Navigate to example.com
        driver.get("https://www.example.com");

        // Get screen size for comparison
        Dimension screenSize = new Dimension(
            Toolkit.getDefaultToolkit().getScreenSize().width,
            Toolkit.getDefaultToolkit().getScreenSize().height
        );

        // Get browser window size
        Dimension windowSize = driver.manage().window().getSize();

        // Assert window is maximized (width and height at least screen size minus some OS taskbar)
        Assertions.assertTrue(windowSize.getWidth() >= screenSize.getWidth() - 50,
            "Browser width should be maximized");
        Assertions.assertTrue(windowSize.getHeight() >= screenSize.getHeight() - 50,
            "Browser height should be maximized");

        // Assert page title contains 'Example Domain'
        String title = driver.getTitle();
        Assertions.assertTrue(title.contains("Example Domain"), "Page title should contain 'Example Domain'");
    }

    @AfterEach
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }
}

This test class uses Selenium WebDriver with Java and JUnit 5.

setUp(): Creates an EdgeOptions object and adds arguments to start the browser maximized and disable notifications. Then it initializes the EdgeDriver with these options.

testEdgeOptionsConfiguration(): Navigates to https://www.example.com. It then compares the browser window size to the screen size to verify the window is maximized (allowing a small margin for OS taskbars). It also asserts the page title contains 'Example Domain'.

tearDown(): Ensures the browser closes after the test to free resources.

This approach uses best practices like configuring browser options explicitly, verifying UI state with assertions, and cleaning up resources.

Common Mistakes - 4 Pitfalls
Not using EdgeOptions and launching EdgeDriver with default settings
Using Thread.sleep() to wait for page load instead of relying on implicit or explicit waits
Not closing the browser after test execution
Hardcoding window size values instead of comparing with screen size
Bonus Challenge

Now add data-driven testing with 3 different URLs and verify the page title contains expected text for each.

Show Hint