0
0
Selenium Javatesting~10 mins

EdgeOptions configuration in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens the Microsoft Edge browser with customized options using EdgeOptions. It verifies that the browser starts with the specified options and navigates to the correct URL.

Test Code - JUnit 5
Selenium Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class EdgeOptionsTest {
    private WebDriver driver;

    @BeforeEach
    public void setUp() {
        EdgeOptions options = new EdgeOptions();
        options.addArguments("--start-maximized");
        options.addArguments("--disable-notifications");
        driver = new EdgeDriver(options);
    }

    @Test
    public void testNavigateToExample() {
        driver.get("https://example.com");
        String currentUrl = driver.getCurrentUrl();
        assertEquals("https://example.com", currentUrl);
    }

    @AfterEach
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }
}
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Create EdgeOptions instance and add arguments '--start-maximized' and '--disable-notifications'EdgeOptions object configured with specified arguments-PASS
2Initialize EdgeDriver with the configured EdgeOptionsMicrosoft Edge browser opens with maximized window and notifications disabled-PASS
3Navigate to 'https://example.com'Browser loads the example.com homepage-PASS
4Get current URL from browserCurrent URL is 'https://example.com'Verify current URL equals 'https://example.com'PASS
5Close the browser using driver.quit()Browser window closes and WebDriver session ends-PASS
Failure Scenario
Failing Condition: EdgeDriver fails to start with the given EdgeOptions or navigation URL is incorrect
Execution Trace Quiz - 3 Questions
Test your understanding
What does the argument '--start-maximized' do in EdgeOptions?
AIt sets the browser to headless mode
BIt disables browser notifications
CIt opens the browser window maximized
DIt clears browser cookies on start
Key Result
Always configure browser options explicitly to control browser behavior during tests, and ensure proper cleanup by closing the browser after tests to avoid resource leaks.