Learn Python with Talk Python's 270 hours of courses

End-to-End Web Testing with Playwright

Episode #368, published Fri, Jun 3, 2022, recorded Thu, May 12, 2022

How do you test whether your web sites are working well? Unit tests are great. But for web apps, the number of pieces that have to click together "just so" are many. You have databases, server code (such as a Flask app), server templates (Jinja for example), CSS, Javascript, and even deployment topologies (think nginx + uvicorn). Unit tests won't cover all of that integration. But Playwright does. Playwright is a modern, Pythonic take on testing webs apps using code driving a browser core to interact with web apps the way real users and API clients do. I think you'll find a lot to like there. And we have Pandy Knight from Automation Panda here to break it down for us.

Watch this episode on YouTube
Play on YouTube
Watch the live stream version

Episode Deep Dive

Guests Introduction and Background

Andrew Knight, often known as "Automation Panda," is a seasoned test automation engineer and developer advocate at Applitools. He has a diverse background working with Python, C#, Java, and more, with a deep interest in modern testing and automation practices. He shares his experiences writing and teaching about testing on his blog, AutomationPanda.com. Andrew has spoken at numerous conferences, created educational materials on testing best practices, and championed the importance of community engagement and mentorship.

What to Know If You're New to Python

If you’re getting started with Python, here are a few essentials so you can fully appreciate the discussion in this episode:

  • Familiarize yourself with the basic Python syntax (functions, packages, the import statement).
  • Understand how to install libraries via pip or a virtual environment tool.
  • Know what automated tests are (even at a simple level) before jumping into advanced frameworks.
  • Be aware that Python can drive many external tools like browsers, thanks to libraries such as Selenium and Playwright.

Key Points and Takeaways

  1. Why End-to-End Web Testing Matters
    End-to-end testing ensures that entire web applications—from the database to the front-end—work cohesively. While unit testing verifies small parts of the code, E2E testing validates user workflows and complex interactions across components. This is vital for modern web apps built with frameworks like Flask, FastAPI, or any JavaScript front-end because it checks real-world scenarios rather than isolated functions.

  2. Unit Tests vs. Integration Tests
    Unit tests check individual pieces of code in isolation, but integration (or feature) tests confirm that multiple parts of the system interact as intended. For web apps, integration tests can uncover issues that unit tests might miss, such as incorrect template bindings or slow-loading dynamic elements.

  3. An Introduction to Playwright
    Playwright is a modern browser automation framework supporting multiple browsers (Chromium, Firefox, and WebKit). It provides an easy-to-use Python API, auto-waits for elements to load, and helps developers build reliable tests more quickly. It’s optimized for concurrency by using concepts like browser contexts, avoiding the need to restart the browser for every test.

  4. Selenium vs. Playwright
    Selenium paved the way for browser-based testing, but it can require extensive manual waits or external layers to handle complex scenarios. Playwright leverages browser debug protocols, making it generally faster and better at auto-waiting for elements. Selenium remains an open-governance standard with broad vendor support, so teams should choose based on project and organizational needs.

  5. Automatic Waiting and Flakiness Reduction
    One of Playwright’s key features is its built-in waiting mechanisms. By automatically waiting for elements to be actionable, it decreases flaky test results and random failures. This is a major benefit for teams that want trustworthy test suites with minimal overhead in synchronizing the UI.

  6. Headless vs. Headed Mode
    Headless mode runs browser tests without displaying the browser, speeding up continuous integration processes. Headed mode lets you visually watch interactions for debugging or local development. Both are valuable—headless for CI pipelines and headed for a quick look into what the test is doing.

  7. Powerful Debugging Tools
    Playwright’s Inspector and Trace Viewer help visualize test flow, network events, and DOM snapshots. They capture videos and screenshots automatically, making it significantly easier to diagnose errors. This reduces guesswork about what happened at the exact moment a test failed.

  8. Managing Authentication and Browser Context
    Playwright’s “browser context” feature enables faster test setups by sharing a single browser process while giving each test a fresh incognito-like environment. You can also store and reuse authenticated states (cookies, sessions) so tests don’t repeatedly log in, cutting down on test time without compromising coverage.

  9. Visual Testing and AI
    Andrew Knight is a Developer Advocate at Applitools, a platform offering automated visual testing. Beyond functional checks, visual testing ensures the page looks correct to human eyes. It identifies unexpected layout shifts, color changes, and misalignments that typical DOM-based tests might overlook.

  10. Testing Beyond Just Web Apps
    Although Playwright and Selenium are known for web application testing, the broader principles extend to APIs, microservices, or even mobile web. Concepts like user-centric checks, visual verification, and concurrency are fundamental to any software testing practice—ensuring apps behave correctly end-to-end.

Interesting Quotes and Stories

  • "When you generate content, that becomes your electronic business card. If you do the things you like, the things you like will start coming to you." – Andrew Knight on building a personal brand through blogging and content creation.
  • “You want to have a lot of faith and trust that a broken build means something.” – On reducing flaky tests to ensure test failures are genuinely important.
  • “Video is lit. It’s incredible.” – Andrew Knight’s excitement over Playwright’s built-in video capture for fast debugging.
  • “People may know me from Automation Panda—there’s no company behind it, it’s just me sharing knowledge.” – Andrew highlighting his passion for open sharing in the testing community.

Key Definitions and Terms

  • Headless Mode: Running a browser without a visible UI, typically used in automated CI pipelines for speed and resource efficiency.
  • Flakiness in Tests: Random and unreliable test results caused by timing issues, race conditions, or not waiting for elements to appear.
  • Browser Context: A feature in Playwright (and some testing tools) that mimics opening a new incognito window, allowing isolated sessions without restarting the entire browser.
  • Visual Testing: Verifying the pixel-perfect layout and appearance of an application, catching UI regressions that functional tests might miss.
  • Auto-Wait/Actionability: A Playwright feature that pauses scripts until certain conditions (like element visibility) are met, reducing the need for manual sleeps.

Learning Resources

Here are a few relevant resources to expand your knowledge on testing in Python and beyond:

Overall Takeaway

End-to-end testing with tools like Playwright provides a vital layer of assurance for modern, dynamic web applications. Andrew Knight’s insights make it clear that reducing flakiness, leveraging auto-waiting, and embracing developer-friendly debugging features are significant game-changers in the testing space. By combining functional and visual testing, teams can deliver robust, high-quality software that meets both technical and user experience standards.

Links from the show

Pandy's Twitter: @AutomationPanda
Pandy's blog: automationpanda.com
Playwright: playwright.dev
Pandy's Playwright tutorial: github.com
pytest: pytest.org
applitools: applitools.com
Screenplay package: pypi.org/project/screenplay
Watch this episode on YouTube: youtube.com
Episode transcripts: talkpython.fm

--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy

Talk Python's Mastodon Michael Kennedy's Mastodon