Selenium Architecture & Setup
Selenium WebDriver is the world's most widely used web automation framework. Before writing your first test, you must understand how Selenium works internally — the Client → WebDriver Protocol → Browser architecture — because this knowledge is what lets you diagnose failures, configure CI environments, and write robust tests that don't break every sprint.
Selenium Architecture
- Selenium WebDriver (W3C WebDriver Protocol): Industry-standard JSON Wire Protocol over HTTP between test code and browser drivers
- Your Test Code → sends HTTP commands → ChromeDriver/GeckoDriver → controls → Chrome/Firefox
- Components: Selenium Client Library (Python/Java/JS/C#), Browser Driver (ChromeDriver, GeckoDriver, EdgeDriver), Browser (Chrome, Firefox, Edge)
- WebDriver Manager: Automatically downloads and manages browser driver versions (recommended: webdriver-manager package)
- Selenium Grid: Allows running tests in parallel across multiple browsers and machines simultaneously
Complete Selenium Setup (Python)
# ══════════════════════════════════════════════════════════════
# SETUP: Install Selenium + Webdriver Manager
# ══════════════════════════════════════════════════════════════
# pip install selenium webdriver-manager pytest
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
# ── Basic Setup ──────────────────────────────────────────────
def get_driver(headless=False):
options = Options()
if headless:
options.add_argument("--headless") # Run without GUI (CI environments)
options.add_argument("--no-sandbox") # Required in Linux CI
options.add_argument("--disable-dev-shm-usage") # Required in Docker
options.add_argument("--window-size=1920,1080")
# WebDriverManager auto-downloads matching ChromeDriver version
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=options)
driver.implicitly_wait(10) # Global wait for element visibility
return driver
# ── First Test — navigates, finds element, verifies title ─────
def test_google_homepage():
driver = get_driver()
try:
driver.get("https://www.google.com")
assert "Google" in driver.title, f"Expected 'Google' in title, got: {driver.title}"
print(f"✅ Page title: {driver.title}")
finally:
driver.quit() # Always quit to release browser resources
# ── pytest conftest.py — shared driver fixture ────────────────
# conftest.py:
import pytest
@pytest.fixture(scope="function") # New driver per test function
def driver():
driver = get_driver(headless=True)
yield driver # Test runs here
driver.quit() # Cleanup after test (even if test fails)
# ── Using the fixture in tests ─────────────────────────────────
def test_page_loads(driver):
driver.get("https://example.com")
assert driver.title == "Example Domain"
def test_page_has_heading(driver):
driver.get("https://example.com")
heading = driver.find_element("tag name", "h1")
assert heading.text == "Example Domain"Common Mistakes
- Not quitting the driver — browser processes accumulate and crash CI machines; always use try/finally or fixtures
- Hardcoding ChromeDriver path — versions mismatch constantly; use webdriver-manager to auto-download the correct version
- Not running headless in CI — CI servers have no display; headless mode is required for GitHub Actions and Jenkins
- Using a single driver instance for all tests — tests become dependent on each other's state; use a fresh driver per test function
Tip
Tip
Practice Selenium Architecture Setup in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Testing pyramid: many unit tests, fewer integration, fewest E2E
Practice Task
Note
Practice Task — (1) Write a working example of Selenium Architecture Setup from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Selenium Architecture Setup is skipping edge case testing — empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready software testing code.
Key Takeaways
- Selenium WebDriver is the world's most widely used web automation framework.
- Selenium WebDriver (W3C WebDriver Protocol): Industry-standard JSON Wire Protocol over HTTP between test code and browser drivers
- Your Test Code → sends HTTP commands → ChromeDriver/GeckoDriver → controls → Chrome/Firefox
- Components: Selenium Client Library (Python/Java/JS/C#), Browser Driver (ChromeDriver, GeckoDriver, EdgeDriver), Browser (Chrome, Firefox, Edge)