0
0
Selenium Javatesting~10 mins

FirefoxOptions configuration in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens Firefox browser with customized options using FirefoxOptions. It verifies the browser starts with the specified options and navigates to the correct URL.

Test Code - JUnit
Selenium Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
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 FirefoxOptionsTest {
    private WebDriver driver;

    @BeforeEach
    public void setUp() {
        FirefoxOptions options = new FirefoxOptions();
        options.addArguments("-private"); // Start Firefox in private mode
        options.setHeadless(true); // Run in headless mode
        driver = new FirefoxDriver(options);
    }

    @Test
    public void testNavigateToExample() {
        driver.get("https://example.com");
        String title = driver.getTitle();
        assertEquals("Example Domain", title);
    }

    @AfterEach
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }
}
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Create FirefoxOptions and add '--private-window' argument and set headless modeFirefoxOptions object configured with private mode and headless true-PASS
2Initialize FirefoxDriver with configured FirefoxOptionsFirefox browser starts in headless private mode-PASS
3Navigate to 'https://example.com'Browser loads the Example Domain page-PASS
4Get page title and assert it equals 'Example Domain'Page title is 'Example Domain'assertEquals("Example Domain", title)PASS
5Quit the browser and clean upBrowser closed, WebDriver session ended-PASS
Failure Scenario
Failing Condition: FirefoxDriver fails to start with given FirefoxOptions or page title does not match
Execution Trace Quiz - 3 Questions
Test your understanding
What does the '--private-window' argument in FirefoxOptions do in this test?
AStarts Firefox in private browsing mode
BEnables headless mode
CDisables JavaScript
DSets browser window size
Key Result
Always configure browser options explicitly to control test environment, such as private mode and headless, ensuring consistent and isolated test runs.