Configure Firefox browser with custom options and verify browser launch
Preconditions (2)
✅ Expected Result: Firefox browser launches with the specified options, navigates to the page, and the page title matches 'Example Domain'
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; public class FirefoxOptionsTest { private WebDriver driver; @BeforeMethod public void setUp() { // Create FirefoxOptions object FirefoxOptions options = new FirefoxOptions(); // Run browser in headless mode options.setHeadless(true); // Disable notifications options.addPreference("dom.webnotifications.enabled", false); // Initialize FirefoxDriver with options driver = new FirefoxDriver(options); } @Test public void testFirefoxOptionsConfiguration() { // Navigate to example.com driver.get("https://www.example.com"); // Verify page title String title = driver.getTitle(); Assert.assertEquals(title, "Example Domain", "Page title should be 'Example Domain'"); } @AfterMethod public void tearDown() { if (driver != null) { driver.quit(); } } }
This test class uses Selenium WebDriver with Java and TestNG framework.
In setUp(), we create a FirefoxOptions object to configure the browser:
We then initialize FirefoxDriver with these options.
The test method navigates to https://www.example.com and asserts the page title is exactly 'Example Domain'.
Finally, tearDown() closes the browser to clean up.
This structure ensures the browser runs with the desired options and the test verifies the expected page loaded correctly.
Now add data-driven testing to run the test with headless mode enabled and disabled
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