0
0
Selenium Pythontesting~10 mins

Browser options and capabilities in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a Chrome browser with specific options to disable notifications and run in headless mode. It verifies the browser title to confirm the page loaded correctly.

Test Code - unittest
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import unittest

class TestBrowserOptions(unittest.TestCase):
    def setUp(self):
        chrome_options = Options()
        chrome_options.add_argument('--disable-notifications')
        chrome_options.add_argument('--headless')
        self.driver = webdriver.Chrome(service=Service(), options=chrome_options)

    def test_google_title(self):
        self.driver.get('https://www.google.com')
        title = self.driver.title
        self.assertEqual(title, 'Google')

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

if __name__ == '__main__':
    unittest.main()
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser is launched with options --disable-notifications and --headlessChrome browser runs in headless mode with notifications disabled-PASS
2Browser navigates to https://www.google.comGoogle homepage is loaded in the headless browser-PASS
3Retrieve the page titlePage title is 'Google'Check if page title equals 'Google'PASS
4Close the browserBrowser session ends-PASS
Failure Scenario
Failing Condition: If the browser fails to launch with the specified options or the page title does not match 'Google'
Execution Trace Quiz - 3 Questions
Test your understanding
What does the '--headless' option do in this test?
ARuns the browser without opening a visible window
BEnables browser notifications
CChanges the browser language to English
DDisables JavaScript on the page
Key Result
Using browser options like '--headless' and '--disable-notifications' helps control browser behavior during tests, making tests faster and less intrusive.