Test Overview
This test opens Firefox with a custom configuration to disable notifications and verifies the browser launches correctly with the set preferences.
This test opens Firefox with a custom configuration to disable notifications and verifies the browser launches correctly with the set preferences.
from selenium import webdriver from selenium.webdriver.firefox.options import Options from selenium.webdriver.firefox.service import Service from selenium.webdriver.common.by import By import unittest class TestFirefoxConfig(unittest.TestCase): def setUp(self): options = Options() options.set_preference("dom.webnotifications.enabled", False) self.driver = webdriver.Firefox(options=options) def test_firefox_launch_with_config(self): self.driver.get("https://www.example.com") element = self.driver.find_element(By.TAG_NAME, "h1") self.assertEqual(element.text, "Example Domain") def tearDown(self): self.driver.quit() if __name__ == "__main__": unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Firefox options are set to disable notifications | Firefox options object created with 'dom.webnotifications.enabled' set to False | — | PASS |
| 2 | Firefox browser is launched with the configured options | Firefox browser window opens without notification prompts | — | PASS |
| 3 | Browser navigates to 'https://www.example.com' | Example Domain page is loaded and visible | — | PASS |
| 4 | Find the <h1> element on the page | <h1> element with text 'Example Domain' is present | Check that the <h1> text equals 'Example Domain' | PASS |
| 5 | Close the browser and end the test | Firefox browser window closes | — | PASS |
FirefoxOptions() in Selenium tests?FirefoxOptions() is used to set browser preferences like headless mode or disable notifications before launching Firefox.FirefoxOptions().options.headless = True is the standard way to enable headless mode for Firefox.set_headless() and enable_headless() are not valid methods. add_argument('--headless') works for Chrome but not recommended for Firefox.from selenium.webdriver import Firefox from selenium.webdriver.firefox.options import Options options = Options() options.headless = True browser = Firefox(options=options) print(browser.capabilities['moz:headless']) browser.quit()
options.headless = True tells Firefox to run without UI, reflected in capabilities under key 'moz:headless' as True.browser.capabilities['moz:headless'], which will be True because headless mode is enabled.from selenium.webdriver import Firefox from selenium.webdriver.firefox.options import Options options = Options() options.headless(True) browser = Firefox(options=options) browser.quit()
options.headless(True) incorrectly calls headless as a method, but it is a property to set.options.headless = True to enable headless mode properly.options.set_preference() to set Firefox-specific preferences like disabling notifications.'dom.webnotifications.enabled' controls notifications; setting it to False disables them.Pass the test and this pattern moves unknown