EdgeOptions configuration in Selenium Java - Build an Automation Script
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.
Now add data-driven testing with 3 different URLs and verify the page title contains expected text for each.