0
0
Selenium Pythontesting~15 mins

Browser profile configuration in Selenium Python - Build an Automation Script

Choose your learning style9 modes available
Configure Firefox browser profile to disable notifications and verify settings
Preconditions (2)
Step 1: Create a new Firefox profile
Step 2: Set the profile preference to disable browser notifications
Step 3: Launch Firefox browser with this profile
Step 4: Navigate to https://www.example.com
Step 5: Verify that the browser notifications are disabled
✅ Expected Result: Firefox browser launches with notifications disabled and loads https://www.example.com successfully
Automation Requirements - Selenium with Python
Assertions Needed:
Verify the browser is launched with the custom profile
Verify the page title contains 'Example Domain' to confirm navigation
Verify that notifications are disabled by checking the profile preference
Best Practices:
Use FirefoxProfile to set preferences before browser launch
Use explicit waits if needed for page load
Use assertions from unittest or pytest for validation
Close the browser after test to free resources
Automated Solution
Selenium Python
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import unittest

class TestFirefoxProfile(unittest.TestCase):
    def setUp(self):
        # Create Firefox profile
        self.profile = webdriver.FirefoxProfile()
        # Disable notifications
        self.profile.set_preference("dom.webnotifications.enabled", False)
        self.profile.update_preferences()

        options = Options()
        # Launch Firefox with the custom profile
        self.driver = webdriver.Firefox(firefox_profile=self.profile, options=options)

    def test_notifications_disabled(self):
        self.driver.get("https://www.example.com")
        # Assert page title contains 'Example Domain'
        self.assertIn("Example Domain", self.driver.title)
        # Verify the preference is set (indirectly, since direct check is not possible via WebDriver)
        # We rely on profile setting correctness here

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()

This test script uses Selenium with Python's unittest framework.

In setUp, we create a Firefox profile and set the preference dom.webnotifications.enabled to False to disable notifications.

We launch Firefox with this profile.

The test navigates to https://www.example.com and asserts the page title contains 'Example Domain' to confirm navigation.

Direct verification of notification settings via WebDriver is not possible, so we trust the profile setting.

Finally, tearDown closes the browser to clean up.

Common Mistakes - 4 Pitfalls
Not setting the profile preferences before launching the browser
Using deprecated FirefoxProfile API or incorrect method names
Not closing the browser after test execution
Trying to verify browser preferences directly via WebDriver commands
Bonus Challenge

Now add data-driven testing with 3 different Firefox profile preferences to disable notifications, disable images, and set a custom homepage

Show Hint