Skip to main content

Blog # 18: ๐Ÿงช Playwright Trace - Your Test's Black Box Recorder

When I first started dabbling in Playwright for automation testing, I was amazed by its power—but honestly, I was intimidated by debugging. Failed tests felt like cryptic puzzles. Why did that button click fail? Was it the DOM? The network?
Then I discovered Playwright Trace Viewer, and it was like getting a magnifying glass to solve my test mysteries. This isn’t just a feature—it’s my trusty debugging sidekick. Here’s how I went from “What went wrong?” to “I’ve got this!” using Trace Viewer.

✨ What is Trace Viewer?

Picture Trace Viewer as a time machine for your tests. It records everything—clicks, navigations, network calls, console logs, and even what the page looked like—and lets you rewind to spot exactly where things went off the rails.
For someone new like me, this was mind-blowing. Here's what Trace Viewer helped me see:

✅ Every action—like a movie script of my test
๐Ÿ–ผ️ Screenshots that said “This is what the page looked like!”
๐ŸŒ Network logs that exposed API failures
๐Ÿ“„ DOM snapshots for inspecting the structure
๐Ÿ’ฅ Error lines from my script, without endless console.log hunts

It's like being a detective with all the clues pinned up on a digital evidence board.

Trace Viewer

๐Ÿ› ️ My First Step: How to Set Trace On

Getting started with tracing was easier than I expected—and gave me instant clarity on failed test cases.

๐Ÿ”น Option 1: CLI Shortcut

This command was my first win:

npx playwright test --trace=on

Then I learned the smarter way for CI runs:

npx playwright test --trace=retain-on-failure
✅ Pro tip: This only saves traces for failed tests and helps avoid massive storage issues.

๐Ÿ”น Option 2: Config File Setup (Set It & Forget It)

Once I realized tracing was gold, I made it permanent in my playwright.config.js:

import { defineConfig } from '@playwright/test';
export default defineConfig({
  use: {
    trace: 'retain-on-failure', // Ideal for CI
  },
});

No more manually passing flags—traces just work when I need them.

๐Ÿ” Cracking Open the Case: How to View the Trace

After running my test, I found a shiny .zip file inside the test-results folder. Time to investigate!

๐Ÿ“ Option 1: Open via CLI

npx playwright show-trace relative path                                                                 Example: npx playwright show-trace test-results/login-test/trace.zip
One command, and BOOM—Trace Viewer opens in the browser, like a full control center for your test run.



๐ŸŒ Option 2: Web Interface (Drag-and-Drop)

Go to: https://trace.playwright.dev

Drag your trace.zip file into the page, and you’re in!

๐Ÿ•ต️‍♂️ The Thrill of the Investigation: Inside Trace Viewer

Using Trace Viewer felt like stepping into a debugging control room. Here’s what I explored:

▶️ Actions Tab
A play-by-play of the test’s moves: page.goto, page.click, and more.
Clicking an action showed the locator and duration. Hovering revealed screenshots and DOM snapshots—actual time travel.

Timeline
I could zoom in on specific moments and spot exactly when things broke (hello, red error line!).

๐Ÿ–ผ️ Screenshots Tab
Polaroid-style captures of the page state—perfect for visual test debugging.

๐ŸŒ Network Tab
Helped me catch a delayed API that was silently breaking a test. Headers, payloads—everything’s visible.

๐Ÿ“‹ Logs Tab
Both browser and script logs, grouped by action. Super helpful for tracking sneaky bugs.

Errors Tab
Pinpointed the exact line of failure and showed the full stack trace.

๐Ÿงพ Metadata & Attachments
From browser version to viewport size—every detail, every clue.

❤️ Why I’m Obsessed

Trace Viewer turned debugging from a chore into an interactive adventure. As a Playwright learner, it’s helped me build confidence to investigate failures without panicking. Instead of guessing or drowning in logs, I follow the clues like a pro.
It’s not just a tool—it’s my debugging superpower.
 

Comments

Popular posts from this blog

Software Testing Heuristics and mnemonics.

Software Testing Heuristics Heuristics are simply experience-based techniques for problem-solving, learning, and discovery. Where an exhaustive search is impractical, heuristic methods are used to speed up the process of finding a satisfactory solution. Examples of this method include using a rule of thumb, an educated guess, an intuitive judgment, or common sense. When you face a problem, you try some solutions that may work. For instance, if you suddenly find your mobile hang, what do you do? You may restart your mobile first. If that doesn’t work, then you may check & update the latest software and uninstall suspicious apps.if that also doesn’t work, then you reset your phone setting ( Factory reset). Most of us try a number of steps to solve our problems. These steps may not always work but we try them because we know that they may work. Following heuristics can apply to absolutely any kind of system with any kind of interface.  1.Abstract  Remove details in a model. S...

Blog # 9: Say Hello to Alerts! Handling Dialog Boxes in Playwright

Alerts and dialogs are common elements in web applications that can interrupt automated test flows if not handled properly. Playwright provides straightforward methods to manage these interruptions, ensuring your tests run smoothly. In this guide, I’ll share how I learned handling three types of dialogs—simple alerts, confirmation boxes, and prompts—using Playwright’s built-in features. Why Handle Dialogs? Dialogs often appear during critical user interactions, such as form submissions, error notifications, or data input requests. If ignored, they can cause tests to freeze or fail. Playwright’s dialog-handling capabilities allow you to: Validate dialog messages. Accept, dismiss, or respond to prompts programmatically. Keep tests resilient and predictable. Let’s explore how to tackle each type of dialog. 1.  Simple Alerts: The One-Way Notification A simple alert is a basic pop-up with an "OK" button. Example Scenario : A basic alert appears, shouting, "I am an alert box!...

Blog # 4 : A Deep Dive into Playwright Assertions

  Ever spent hours debugging a test only to realize you forgot to check if a button was actually clickable? In web testing, the devil's in the details—and that's where assertions become your best friend. Let's explore how Playwright's assertion library can transform your testing strategy, using the popular The Internet testing playground. Why Assertions Matter Assertions are the backbone of any meaningful test. They're the checkpoints that scream, "This works!" or "Something's broken here!" Playwright's built-in expect library shines when testing real-world scenarios like authentication flows and dynamic content. Let's Start Testing: A Real-World Scenario We'll be testing key features of The Internet playground. Here's our foundation: Now let's add powerful assertions. Validating Content: Is What You See What You Get? 1. Page Titles: Your First Line of Defense Verify you're on the correct page immediately after na...

Day 15 Name five different online payment methods.

Most modern online payment services offer easy-to-use, fast and secure ways to pay Here’s a list of some of the most popular online payment services: Digital Wallet ( E wallet) A digital wallet refers to software, an electronic device, or an online service that enables individuals or businesses to make transactions electronically. It stores the payment information of users for different payment modes on various websites.                           PayPal PayPal is one of the most dominant payment methods available today. over 20 million UK shoppers use PayPal each year in the UK and  7 million businesses worldwide use their platform to accept payments. PayPal is an eCommerce payment processing company that allows users to set up a PayPal account and pay a fee for each cash transaction. Many customers prefer to checkout with PayPal because it’s so simple and quick to use. Amazon Pay Amazon Pay is another ...

What is Agile?

                              Recently I did a presentation after almost 20 years at a Bootcamp showcase on Agile. As Agile celebrated its 20th anniversary this year I decided to talk on what Agile is? Below are the few drops from Agile's ocean which I managed to pour during my showcase. What is Agile Software Development? Agile is a time boxed, iterative approach to software delivery that builds software incrementally from the start of the project, instead of trying to deliver it all at once near the end. It works by breaking projects down into little bits of user functionality called user stories, prioritizing them, and then continuously delivering them in short time cycles called iterations.                In iterative development, feature code is designed, developed and tested in repeated cycles. With each iteration, additional features can...

What is Quality

  ✨ What is Quality? Quality means different things to different people. For some, the brand Apple ๐Ÿ is synonymous with quality. For others, it’s difficult to define quality, but surprisingly easy to recognize based on their experiences. A quality product or service is one that satisfies customer needs and meets (or even exceeds!) their expectations. When you receive quality, in whatever form, you're eager to get more. You want to return for another purchase, refer the product to friends, and talk about it publicly. Quality is what we should aim for to ensure returning customers and a strong brand as a company. According to IEEE , quality is defined as “The degree to which a component, system, or process meets specified requirements and/or user/customer needs and expectations.” ๐Ÿ“ˆ ๐Ÿ‘ฅ Who is Responsible for Software Quality?   Everyone involved in a software project—including the Product Owner , Scrum Master , Developer , Tester , and other stakeholders such as the Business ...

Risk Storming for Vending Machine

  In the 4th session of Testing Bootcamp Beth Marshall introduced us to a very interesting game of Risk Storming. It's a  collaborative and visual technique for identifying risk and planning the Test Strategy accordingly .You can  use a Test Sphere card deck from Ministry of Testing or go to https://riskstormingonline.com/   Risk Storming takes you through three phases to get the answers. Which quality aspects matter most for your product? What risks could impact these important aspects? How can you test to make sure those risks don’t happen?     Our task was to risk storming to test the Vending Machine . And here is my take on it.                               Quality Aspect Functionality  Does it accept and return both coin and cash correctly? BOUNDARY VALUE TESTING Does it drop the selected product correctly? INTEGRATION TESTING , BUSINESS SCENARIOS , PURPOSE Is the k...