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.
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.
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(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Create FirefoxOptions and add '--private-window' argument and set headless mode | FirefoxOptions object configured with private mode and headless true | — | PASS |
| 2 | Initialize FirefoxDriver with configured FirefoxOptions | Firefox browser starts in headless private mode | — | PASS |
| 3 | Navigate to 'https://example.com' | Browser loads the Example Domain page | — | PASS |
| 4 | Get page title and assert it equals 'Example Domain' | Page title is 'Example Domain' | assertEquals("Example Domain", title) | PASS |
| 5 | Quit the browser and clean up | Browser closed, WebDriver session ended | — | PASS |
FirefoxOptions in Selenium Java?FirefoxOptions object and add the argument --headless in Java?addArguments(String... args).addArguments("--headless") which is correct. FirefoxOptions options = new FirefoxOptions(); options.setHeadless(true); uses a non-existent method setHeadless. Options C and D use incorrect method names or argument formats.FirefoxOptions options = new FirefoxOptions();
options.setAcceptInsecureCerts(true);
FirefoxDriver driver = new FirefoxDriver(options);
driver.get("https://expired.badssl.com/");FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.startup.homepage", "https://example.com");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
FirefoxDriver driver = new FirefoxDriver();new FirefoxDriver() without passing the configured options.options, the profile settings are ignored and default Firefox starts.FirefoxOptions for this scenario?permissions.default.image set to 2.Pass the test and this pattern moves unknown