0
0
Selenium Pythontesting~15 mins

Chrome configuration in Selenium Python - Build an Automation Script

Choose your learning style9 modes available
Configure Chrome browser to start maximized and disable notifications
Preconditions (2)
Step 1: Create a ChromeOptions object
Step 2: Add argument to start Chrome maximized
Step 3: Add argument to disable browser notifications
Step 4: Launch Chrome browser with these options
Step 5: Navigate to https://www.example.com
Step 6: Verify the browser window is maximized
Step 7: Verify no notification popups appear on the page
✅ Expected Result: Chrome browser opens maximized without showing any notification popups on https://www.example.com
Automation Requirements - Selenium with Python
Assertions Needed:
Verify browser window size matches screen size (maximized)
Verify no notification permission popup is present
Best Practices:
Use ChromeOptions to configure browser settings
Use explicit waits if needed
Use assertions from unittest or pytest
Close browser after test
Automated Solution
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import unittest

class TestChromeConfig(unittest.TestCase):
    def setUp(self):
        options = Options()
        options.add_argument('--start-maximized')
        options.add_argument('--disable-notifications')
        self.driver = webdriver.Chrome(options=options)

    def test_chrome_configuration(self):
        self.driver.get('https://www.example.com')

        # Verify window is maximized by comparing window size to screen size
        window_size = self.driver.get_window_size()
        screen_width = self.driver.execute_script('return screen.width')
        screen_height = self.driver.execute_script('return screen.height')

        self.assertEqual(window_size['width'], screen_width, 'Window width is not maximized')
        self.assertEqual(window_size['height'], screen_height, 'Window height is not maximized')

        # Verify no notification permission popup by checking absence of notification permission dialog
        # This is a simple check: no alert present
        try:
            alert = self.driver.switch_to.alert
            alert_text = alert.text
            self.fail(f'Unexpected alert present: {alert_text}')
        except Exception:
            # No alert present, pass
            pass

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

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

The setUp method creates a ChromeOptions object and adds two arguments: --start-maximized to open the browser maximized, and --disable-notifications to block notification popups.

The test navigates to https://www.example.com. It then checks the browser window size matches the screen size by running JavaScript to get screen width and height and comparing to the window size.

To verify no notification popup appears, it tries to switch to an alert. If an alert is present, the test fails. If no alert is found, it passes.

The tearDown method closes the browser after the test.

This structure uses unittest framework for clear setup, test, and cleanup phases.

Common Mistakes - 4 Pitfalls
Not using ChromeOptions to configure browser
Using hardcoded window size values to check maximization
Ignoring notification popups by not checking alerts
Not closing the browser after test
Bonus Challenge

Now add data-driven testing to launch Chrome with different sets of options: maximized only, disable notifications only, and both combined.

Show Hint