Leanpub Header

Skip to main content

Practical Web Test Automation with Playwright and Pytest

Test web applications wisely with Playwright and Pytest

Practical Web Test Automation with Playwright and Pytest
This book is 100% completeLast updated on 2026-09-06

Most teams still struggle with flaky, slow, and hard-to-maintain UI tests. Practical Web Test Automation with Playwright and Pytest shows you a battle-tested way to build reliable, maintainable automated tests that actually keep up with rapid releases.

Minimum price

$25.00

$40.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
About

About

About the Book

While few people question the value of test automation, comprehensive automated testing through the UI (the browser for web applications) is still uncommon in most software projects. Attempts often fail for three familiar reasons:

  • Difficult to learn — test scripts become complex and the tools are hard to master
  • Hard to maintain — UI tests break easily when the application changes
  • Long feedback loop — automated suites take too long to run

Success requires overcoming all three challenges.


This book shows a practical, battle-tested approach to implementing reliable UI test automation for web applications. You will learn:

  • Develop high-quality Playwright (Python) tests efficiently
  • Apply maintainable test design principles
  • Functional Testing Refactoring
  • Setting up a continuous testing server to run large suites of automated UI tests efficiently
  • Proven strategies for team collaboration and successful test-automation adoption across projects and organizations

Share this book

Author

About the Author

Courtney Zhan

Courtney Zhan is a Software Development Engineer at Amazon Japan, with a passion for end-to-end test automation, programming, continuous testing, and graphic design. She shares tips and insights on test automation and continuous testing weekly on Medium and Substack. Courtney is the published author of Selenium WebDriver Recipes in C# by Apress, and 21 of her articles have been featured on software testing newsletters.

Contents

Table of Contents

Table of Contents

  • Forward
  • Preface
    • What is unique about this book?
    • Who should read this book?
    • How to read this book?
    • Send me feedback
  • 1: What is Web Test Automation?
    • 1.1: Test automation benefits
    • 1.2: Reality check
    • 1.3: Reasons for test automation failures
    • 1.4: Successful web test automation
    • 1.5: Why Playwright framework?
    • 1.6: Why pytest and Python language?
    • 1.7: Learning approach
    • 1.8: Next action
  • 2: Test Execution Environment Setup
    • 2.1: Install Python with pyenv (recommended)
    • 2.2: Install Playwright and pytest
    • 2.3: Alternative Python setup: system wide
    • 2.4: Alternative Python setup: with venv
    • 2.5: Review
  • 3: First Automated Test
    • 3.1: Test Design
    • 3.2: Installing TestWise (under 1 minute)
    • 3.3: Create Automated Test
    • 3.4: Create a test case
  • 4: How Automated Testing works
    • 4.1: Web test automation rhythm
    • 4.2: Test syntax frameworks
    • 4.3: pytest execution hooks
    • 4.4: Run pytest tests from the command line
    • 4.5: Review
  • 5: Test Tool
    • 5.1: TestWise: Next-Gen Functional Testing IDE
    • 5.2: Visual Studio Code Programming Editor
    • 5.3: PyCharm Development IDE
    • 5.4: Review
  • 6: Playwright Syntax in Nutshell
    • 6.1: Browser, Context, and Page
    • 6.2: Playwright locators
    • 6.3: get_by_role()
    • 6.4: get_by_label()
    • 6.5: get_by_placeholder()
    • 6.6: get_by_text()
    • 6.7: get_by_test_id()
    • 6.8: locator() with CSS/XPath
    • 6.9: Page-level convenience methods
    • 6.10: Locator chaining
    • 6.11: Multiple matching elements
    • 6.12: Playwright vs Selenium WebDriver
    • 6.13: Review
  • 7: Gain Productivity
    • 7.1: Playwright CodeGen
    • 7.2: Playwright Trace Viewer
    • 7.3: Some Generic IDE Features
    • 7.4: Keyboard shortcuts
    • 7.5: More TestWise productivity features
    • 7.6: Review
  • 8: Case Study
    • 8.1: Test site
    • 8.2: Preparation
    • 8.3: Create a test project
    • 8.4: Test Suite: Sign in
    • 8.5: Test Suite: Select Flights
    • 8.6: Enter passenger details
    • 8.7: Book confirmation after payment
    • 8.8: Run all tests
    • 8.9: Review
  • 9: Maintainable Functional Test Design
    • 9.1: Record/Playback leads to unmaintainable test scripts
    • 9.2: Success criteria
    • 9.3: Maintainable automated test design
    • 9.4: Maintain with ease
    • 9.5: Case Study: refine test scripts
  • 10: Test Automation Characteristics
    • 10.1: Specific
    • 10.2: Clean
    • 10.3: Independent
    • 10.4: Frequent
    • 10.5: Focused
    • 10.6: Programmable
    • 10.7: Creative
    • 10.8: Sustainable
    • 10.9: Review
  • 11: Functional Test Refactoring
    • 11.1: Code refactoring
    • 11.2: Functional test refactoring
    • 11.3: Tool support
    • 11.4: Case study
    • 11.5: Summary
    • 11.6: Review
  • 12: Set up Continuous Execution
    • 12.1: Conventional Playwright test execution in CI/CD is suboptimal
    • 12.2: BuildWise CT server setup
    • 12.3: Sequential Execution
    • 12.4: Parallel execution
    • 12.5: Review
  • 13: Preparing for Real-World Test Automation
    • 13.1: Syntax errors
    • 13.2: Beyond syntax errors
    • 13.3: Set up source control
    • 13.4: Test Data
    • 13.5: Choose Robust Locators
    • 13.6: Stabilize Tests
    • 13.7: Test script maintenance is the primary effort
    • 13.8: Custom libraries
    • 13.9: Debugging
    • 13.10: What is the best learning method?
    • 13.11: Review
  • 14: Team Collaboration
    • 14.1: Pre-requisite
    • 14.2: Developer-Tester Collaboration Scenario 1: “It worked on my machine”
    • 14.3: Developer-Tester Collaboration Scenario 2: Programmers help QA engineers with technical challenges
    • 14.4: Developer-Tester Collaboration Scenario 3: Acceptance Test-Driven Development
    • 14.5: Business Analysts find E2E test automation useful too
    • 14.6: Review
  • 15: Clarifications
    • 15.1: Real E2E Test Automation is far more challenging than coding
    • 15.2: Neither possible or necessary to achieve 100% coverage
    • 15.3: Gherkin BDD Framework
    • 15.4: Headless testing
    • 15.5: Codeless/Scriptless Test Automation
    • 15.6: AI/Agentic Test Automation
    • 15.7: Cross-browser functional testing
    • 15.8: Data-Driven Test
    • 15.9: Review
  • 16: Adopting End-to-End Test Automation
    • 16.1: Seek executive sponsorship
    • 16.2: Choose a test framework
    • 16.3: Select a test tool
    • 16.4: Run as part of the CI/CD pipeline
    • 16.5: Find a mentor
    • 16.6: Manage expectations
    • 16.7: Solo test automation
    • 16.8: Common mistakes
    • 16.9: Review
  • 17: AI Won’t Replace Real Human E2E Test Automation
  • Afterword
  • Appendix 1: Functional Test Refactoring Catalog
    • Extract Function
    • Move Test Scripts
    • Extract to Page Class
    • Introduce Page Object
    • Rename
  • Appendix 2: Case Study: Test Automation in WhenWise App Development
    • Build Stats
    • Questions and Answers
  • Resources
    • Books
    • Tools
    • Blog
  • References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub