0
0
Selenium Pythontesting~10 mins

Headless mode for CI in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a web page in headless mode using Selenium WebDriver in Python. It verifies that the page title matches the expected title, ensuring the test can run in a Continuous Integration (CI) environment without opening a browser window.

Test Code - unittest
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import unittest

class TestHeadlessMode(unittest.TestCase):
    def setUp(self):
        options = Options()
        options.headless = True
        self.driver = webdriver.Chrome(options=options)

    def test_page_title(self):
        self.driver.get('https://example.com')
        title = self.driver.title
        self.assertEqual(title, 'Example Domain')

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

if __name__ == '__main__':
    unittest.main()
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome WebDriver is initialized with headless option enabledChrome browser runs in headless mode (no visible window)-PASS
2Driver navigates to 'https://example.com'Page loads in headless browser-PASS
3Driver retrieves the page titlePage title is 'Example Domain'Check if page title equals 'Example Domain'PASS
4Driver quits and browser session endsNo browser processes running-PASS
Failure Scenario
Failing Condition: Page title does not match 'Example Domain' or page fails to load
Execution Trace Quiz - 3 Questions
Test your understanding
Why is headless mode used in this test?
ATo run tests without opening a visible browser window
BTo slow down the test execution
CTo open multiple browser windows
DTo disable JavaScript on the page
Key Result
Using headless mode allows tests to run in environments without a graphical interface, such as CI servers, making automated testing faster and resource-efficient.