The three most common Python test automation tools — Selenium, Playwright, and pytest — each have different strengths, and choosing the right one for your purpose is the key to building an effective test suite.
📌 This article is for:
- Engineers unsure whether to use Selenium or Playwright
- Developers wondering how pytest differs from browser automation tools
- QA engineers and developers starting test automation with Python
- Team leads who want a clear rationale for their tool choice
✅ What you’ll learn in this article
- The characteristics and strengths of Selenium, Playwright, and pytest
- A side-by-side comparison of all three tools
- Which tool to use in which situation
- The most common tool combinations used in real projects
📌 The Bottom Line
Selenium wins on browser compatibility and a massive knowledge base. Playwright is modern, fast, and feature-rich. pytest is the test management foundation — not a browser tool. In practice, “pytest + Selenium” or “pytest + Playwright” is the standard combination.
“Should I use Selenium or Playwright?” “How is pytest different from Selenium?” — these are among the most common questions when starting out with test automation in Python.
The key insight is that these three tools serve different roles. Selenium and Playwright are browser automation tools. pytest is a test execution and management framework. Understanding what each one does — and what it doesn’t — makes choosing the right combination straightforward.
Quick Comparison: All Three Tools at a Glance
Let’s start with a high-level overview of where each tool fits.
| Tool | Category | Strengths | Speed | Learning Curve |
|---|---|---|---|---|
| 🌐 Selenium | Browser automation | Cross-browser · Proven track record | 🏃 Moderate | Moderate |
| 🎭 Playwright | Browser automation | Fast · Recording · Auto-wait | ⚡ Fast | Low |
| 🧪 pytest | Test management framework | Unit · API · Test orchestration | ⚡ Fast | Low |
① Selenium
What it is
- The industry standard for browser automation since 2004 — unmatched in track record and available resources
- Excellent cross-browser support: Chrome, Firefox, Safari, Edge, and more
- Multi-language support (Python, Java, JavaScript, C#) makes it easy to adopt in existing projects
Selenium is a tool that automates real browsers to test web applications. It controls browsers through WebDriver, automating clicks, form inputs, page navigation, and more. Its long history means there’s an enormous amount of documentation, Stack Overflow answers, and code samples — making it easy to find solutions when you get stuck.
✅ When to choose Selenium
- Cross-browser testing across real browsers is required
- Your team uses Java or C#
- Inheriting an existing Selenium test suite
- You prioritize the depth of available resources
⚠️ Watch out for
- Wait logic (WebDriverWait) must be written manually
- Slightly slower execution than Playwright
- Screenshot and video recording require extra setup
| Languages | Python / Java / JavaScript / C# / Ruby |
| Browsers | Chrome / Firefox / Safari / Edge (full cross-browser ◎) |
| Install | pip install selenium |
| GitHub Stars | ~31,000 ⭐ (as of March 2026) |
▼ Selenium Code Sample (Python)
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get("https://example.com/login")
# Wait for element, then interact
wait = WebDriverWait(driver, 10)
email = wait.until(EC.presence_of_element_located((By.ID, "email")))
email.send_keys("test@example.com")
driver.find_element(By.ID, "password").send_keys("password123")
driver.find_element(By.ID, "submit").click()
driver.quit()
WebDriverWait instead of time.sleep() — it waits for the element to actually be ready before interacting. This single change eliminates the majority of flaky test failures.
② Playwright
What it is
- A modern browser automation tool developed by Microsoft, released in 2020
- Auto-wait built in — no need to manually write wait logic for elements
- Screenshots, video recording, and trace viewer included out of the box — evidence collection is effortless
Playwright was designed to solve the pain points of Selenium. Its Auto-wait feature automatically waits for elements to be ready before interacting — eliminating the manual wait code that Selenium requires. It’s faster, more stable, and ships with built-in video recording and network interception as standard features.
✅ When to choose Playwright
- Starting a new project from scratch
- Screenshots and video recording are needed
- Test stability is a top priority
- Your team uses Python, JavaScript, or TypeScript
⚠️ Watch out for
- Fewer resources than Selenium (released in 2020)
- Java and C# support is more limited than Selenium
- First install is heavier (downloads browser binaries)
| Languages | Python / JavaScript / TypeScript / Java / C# |
| Browsers | Chromium / Firefox / WebKit (Safari equivalent) |
| Install | pip install playwright → playwright install |
| GitHub Stars | ~68,000 ⭐ (as of March 2026 · rapidly growing) |
▼ Playwright Code Sample (Python)
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto("https://example.com/login")
# Auto-wait: automatically waits for elements before interacting
page.fill("#email", "test@example.com")
page.fill("#password", "password123")
page.click("#submit")
# Screenshot in one line
page.screenshot(path="login_result.png")
browser.close()
page.fill() and page.click() automatically wait for elements to be visible and ready. The “element not found” errors that plague Selenium tests drop dramatically. And page.screenshot() in one line makes evidence collection effortless.
③ pytest
What it is
- A framework for running and managing Python tests
- Used as the foundation for unit tests, API tests, and integration tests
- Can also manage E2E tests by combining with Selenium or Playwright
pytest is not a browser automation tool like Selenium or Playwright — it’s a framework for managing and executing tests. It handles test discovery, execution, and result reporting. Simple assert statements make verification clean and readable, and the fixture system provides a powerful way to share setup and teardown logic across tests.
✅ When to use pytest
- Managing Python unit tests and API tests
- Integrating tests into CI/CD pipelines
- Running and reporting across multiple test files
- Managing Selenium or Playwright test suites
⚠️ Watch out for
- Does not control browsers on its own
- E2E tests require Selenium or Playwright separately
- Python only (other languages use different frameworks)
| Language | Python only |
| Main uses | Unit tests / API tests / Test management / CI integration |
| Install | pip install pytest |
| GitHub Stars | ~12,000 ⭐ (as of March 2026) |
▼ pytest Code Sample
import pytest
import requests
# API test example
def test_get_user():
response = requests.get("https://jsonplaceholder.typicode.com/users/1")
assert response.status_code == 200
assert response.json()["name"] == "Leanne Graham"
# Fixture: define shared setup logic
@pytest.fixture
def base_url():
return "https://jsonplaceholder.typicode.com"
def test_post_created(base_url):
response = requests.post(f"{base_url}/posts", json={"title": "test"})
assert response.status_code == 201
Selenium vs Playwright: Head-to-Head Comparison
Since Selenium and Playwright compete directly as E2E tools, here’s a detailed breakdown of how they differ.
| Category | 🌐 Selenium | 🎭 Playwright |
|---|---|---|
| Released | 2004 (long history) | 2020 (modern) |
| Wait Handling | Must write manually | Auto-wait (built-in) |
| Execution Speed | Slightly slower | Faster |
| Screenshots | Requires setup | One line |
| Video Recording | Not built-in | Built-in standard |
| Resources & Docs | Vastly more | Growing fast |
| Cross-browser | ◎ (real browser drivers) | ◎ (Chromium / Firefox / WebKit) |
🤔 Which should you pick?
| Choose Selenium if… | You’re inheriting existing tests / Your team uses Java or C# / You need the deepest resource pool |
| Choose Playwright if… | You’re starting fresh / Your team uses Python or JS / Stability and speed are the priority |
Common Tool Combinations Used in Real Projects
These three tools aren’t used alone — they’re combined. Here are the two most common patterns in production.
🌐 Pattern ①
pytest + Selenium
The classic combo for teams with existing Selenium test suites. pytest manages and runs tests; Selenium drives the browser.
pytest → test management
selenium → browser control
requests → API tests
🎭 Pattern ②
pytest + Playwright
The current best practice for new projects. Combines Playwright’s stability and speed with pytest’s management and reporting capabilities.
pytest → test management
playwright → browser control
requests → API tests
📖 See each tool in action
Summary
In this article, we compared the three major Python test automation tools — Selenium, Playwright, and pytest — and covered when and how to use each one.
📋 Key Takeaways
- Selenium: long history, massive resources, excellent cross-browser support — requires manual wait logic
- Playwright: modern, fast, Auto-wait and recording built-in — best choice for new projects
- pytest: not a browser tool — it’s the test management and execution framework that Selenium and Playwright run inside
- The standard real-world combination is “pytest + Selenium” or “pytest + Playwright”
- For new Python projects, “pytest + Playwright” is the current best practice
“Which is better?” is less important than “just start using one.” Either tool will teach you the fundamentals of test automation — and you can always switch later.
Want to see Playwright in action? Start with E2E Test Automation with Playwright (Beginner’s Guide) 👇
