Run and Debug Tests Efficiently With Playwright UI Mode

Explore how Playwright UI Mode streamlines test execution with live previews, visual debugging, and faster root-cause identification.

Get Started free
Running and Debugging Tests With Playwright UI Mode
Home Guide Running and Debugging Tests With Playwright UI Mode

Running and Debugging Tests With Playwright UI Mode

A test fails, but no one knows why. The code looks fine, the logs look normal, and rerunning it sometimes makes the failure disappear altogether. It feels like the UI is doing something the test can’t quite capture-loading a bit late, shifting during animation, or rendering differently in CI.

Playwright’s UI Mode helps cut through that uncertainty. Instead of digging through text logs, testers can watch the test run live, see which element is clicked, how the page responds, and exactly where things start to drift.

Overview

Best Practices for Running and Debugging with UI Mode in Playwright

  • Run tests with trace mode enabled
  • Avoid arbitrary delays
  • Debug selector accuracy early
  • Keep the test runner isolated
  • Use step-through execution for multi-phase flows

The sections ahead explain how UI Mode works, how to use it for clearer debugging, and how combining it with real-browser testing ensures those fixes hold across environments.

What is Playwright UI Mode?

Playwright UI Mode is an interactive runner that renders test execution visually. Instead of streaming results to the terminal, it brings up a dedicated window showing test lists, execution state, timelines, locators, and live previews. The interface helps identify behavior that is difficult to capture through logs alone.

For example, visibility problems caused by rapid DOM mutations or hydration delays become apparent when viewed frame by frame.

UI Mode also integrates directly with Playwright’s trace viewer format. When tests run inside the UI, trace data can appear as snapshots, allowing testers to inspect the state of the application exactly as Playwright interacted with it. This gives interactive context to failures involving transitions, race conditions, or flaky selectors.

How to Launch UI Mode

Initiating UI Mode requires no extra configuration. Playwright Test includes a built-in flag that switches from terminal output to interactive mode. After installing dependencies and enabling test configurations, UI Mode can be launched using:

npx playwright test –ui

Running this command opens a dedicated interface. The left panel lists all test files and test cases. The center panel displays execution progress, logs, and inline actions. A preview panel shows the live browser screen during execution. This setup allows switching between tests instantly, pausing execution, or drilling into traces generated during each run.

Developers can also pass a file or directory path to limit what UI Mode loads. This is helpful for debugging a specific area of the suite without pulling in unrelated tests.

Core UI Mode Features

Before exploring how to debug effectively, it is necessary to understand the capabilities included in UI Mode.

  • Live Execution Preview: UI Mode shows the browser as tests run. Testers can watch each step fire, observe how elements load, and detect misaligned animations or delayed UI renders that often escape traditional log-based debugging.
  • Action Explorer: The interface logs each action that Playwright performs: locator clicks, text matches, network waits, and navigation events. Selecting an action highlights corresponding UI states. This helps identify incorrect selectors, timing assumptions, or assertions that depend on unpredictable visual states.
  • Timeline View: The timeline exposes event durations. For instance, if a page load consistently runs slower in a particular test, the timeline helps isolate the cause. Slow evaluations, heavy script bundles, or repetitive selector checks become visible.
  • Trace Integration: When traces are enabled, UI Mode loads them natively. Testers can scroll through each snapshot, see DOM definitions, review console logs, and examine network responses. This is useful when reviewing errors related to dynamic state changes across multi-step user flows.
  • Parallel Control: UI Mode supports switching between parallel workers. This allows isolation of issues that surface only under parallel execution.

Using UI Mode to Debug Tests

Debugging in UI Mode focuses on exposing the root cause visually rather than through guesswork. Testers can pause execution at any step and examine the current page state. This is particularly effective for issues involving locators or timing-sensitive operations.

To start debugging, Playwright allows adding .debug() into the test code:

await page.locator(‘#submit’).debug();

When running in UI Mode, this pauses the test and shows the application state at that exact moment. Testers can inspect the DOM, review computed styles, and interact with the preview window manually. Pausing before navigations or after async interactions reveals problems like missing waits, incorrect selectors, or elements hidden behind overlays.

Breakpoints added through VS Code also synchronize with UI Mode. Combined with the live preview, this creates a controlled debugging sequence where code stepping and visual detection work together. Failures are easier to analyze because the UI captures the state of the application as the assertion fails, rather than after tear-down.

UI Mode helps visualize failures, but confirming those issues requires testing outside the local machine. BrowserStack Automate-a cloud platform for running Playwright tests on real browsers and devices-captures videos, logs, and network data that expose problems UI Mode alone may miss. Its managed infrastructure and parallel execution ensure every debug session reflects real-world conditions

Playwright Testing

Limitations in Playwright UI Mode

UI Mode works best for single-environment debugging, but it does not replace full cross-browser testing. Several limitations make it necessary to combine UI Mode with additional strategies.

  • Inconsistent issues between environments: A test may pass in UI Mode on a local machine while failing in CI or specific browser versions. Rendering engines differ, sometimes subtly, affecting selector matching, layout stability, or network timings.
  • Missing mobile and device-level coverage: UI Mode emulates devices but cannot reproduce real hardware effects like pixel ratios, viewport cutouts, mobile keyboards, or touch-specific interactions.
  • Limited reproduction of network variability: UI Mode cannot fully replicate real throttling, cellular conditions, or cross-region latencies that influence async behavior.
  • No insight into system-level resource contention: Tests involving heavy rendering or high CPU draw may behave differently across devices. Local execution does not reveal these discrepancies.

Recognizing these constraints ensures teams do not rely solely on UI Mode for validation but instead pair it with cross-platform execution.

Best Practices for Running and Debugging with UI Mode in Playwright

Before relying heavily on UI Mode, it is important to follow structured practices that ensure stable, reproducible test runs.

  • Run tests with trace mode enabled: Traces enrich UI Mode by supplying snapshots and logs. This creates a dual perspective: real-time execution in the preview window and recorded evidence for later inspection.
  • Avoid arbitrary delays: Hard-coded waits interrupt the clarity of UI Mode’s timing insights. Using built-in Playwright auto-waiting ensures that UI Mode displays accurate action-to-render chain timing.
  • Debug selector accuracy early: UI Mode highlights locator targets. Reviewing these during development helps eliminate flakiness caused by dynamic classes or fragile DOM structures.
  • Keep the test runner isolated: Running too many tests at once can clutter the interface and hide timing anomalies. Limiting UI Mode to the relevant files helps focus debugging attention where needed.
  • Use step-through execution for multi-phase flows: Complex checkout or login flows benefit from pausing between each action. UI Mode’s controlled execution makes it easier to spot where transitions behave unexpectedly.

UI Mode surfaces timing and interaction issues, but best-practice debugging needs validation across genuine environments. BrowserStack Automate, a cloud-based platform for executing Playwright tests at scale, provides instant access to real browsers and devices plus a unified debugging dashboard with traces, logs, and recordings. This removes local limitations and strengthens CI/CD stability.

Talk to an Expert

When to Use UI Mode vs Traditional Debugging Methods?

UI Mode excels at uncovering timing and interaction-related issues. It should be prioritized when:

  • A test intermittently fails without clear logs.
  • Locators behave inconsistently.
  • Transitions or animations produce unstable UI states.
  • Multi-step flows seem to break at different points on each run.

Traditional debugging tools, including console logs and breakpoints, remain useful when:

  • Errors occur before the UI loads.
  • Environment variables or backend configurations cause failures.
  • Network dependencies require deep inspection.
  • The issue impacts multiple services or layers of the application.

Combining both approaches ensures that investigations cover both visual and system-level causes.

Enhancing Test Runs with Real Browsers via BrowserStack Automate

To overcome the gaps of local UI Mode execution, teams can integrate their Playwright tests with a cloud-based testing tool like

BrowserStack Automate. This combination provides visibility across real browsers, devices, and operating systems while preserving the debugging advantages of Playwright’s UI and trace modes.

Here is an overview of how Automate strengthens the reliability of UI Mode-driven test debugging:

  • Runs Playwright tests on real desktop and mobile browsers so teams can verify selectors, interactions, and animations under true rendering conditions.
  • Provides access to device-specific behaviors such as touch events, viewport resizing, and hardware-level variations that cannot be reproduced locally.
  • Automatically generates videos, logs, console output, network captures, and trace artifacts that align with UI Mode debugging workflows.
  • Enables large-scale parallel execution to validate tests across environments without slowing down development cycles.

Automate expands the debugging toolkit by matching UI Mode precision with production-grade test coverage across browsers and devices.

Try BrowserStack Automate

Conclusion

Playwright UI Mode offers a comprehensive visual environment for examining how tests interact with real application states. It brings clarity to timing uncertainties, dynamic DOM changes, and flaky selector logic by exposing the browser view as tests execute. UI Mode becomes significantly more effective when paired with real browser and device coverage, which is where BrowserStack Automate strengthens the workflow.

BrowserStack Automate enables test execution on thousands of real devices and desktop browsers, ensuring that UI Mode insights translate into stable cross-environment behavior. Combined with Automate’s logs, videos, network traces, and parallel execution, testers gain a dependable path from debugging to production-ready validation.

If you want, this can now be converted into a full-length SEO article with nested subheadings and additional examples.

Tags
Playwright
Unable to Debug Flaky Tests in Playwright UI Mode?
Run Playwright tests with BrowserStack Automate to uncover UI issues, timing gaps, and failures your local setup can’t reveal.

Get answers on our Discord Community

Join our Discord community to connect with others! Get your questions answered and stay informed.

Join Discord Community
Discord