Tip #2

The "Spinner of Death" (Testing Latency)

Update: See how latency leads to duplicate payments in Tip #5: The Rage Click.

Why 0ms latency on localhost hides your worst race conditions.

The Problem: The "Localhost" Bias

Your Machine

NetworkGigabit Fiber
Latency~0.5 ms
"Works on my machine!" šŸš€

User in Subway

Network H+ / Edge
Latency2000 - 5000 ms
  • User double-clicks "Submit" (Charge x2)
  • Spinner stuck forever

The Solution: Proper Throttling

Don't use time.sleep()

This just pauses the test execution script. The browser is still blazing fast. It doesn't simulate network queues or slow packets.

RECOMMENDED

Do use Network Throttling (CDP)

Tell the browser engine itself: "Pretend you are on a 50kb/s connection". This forces the browser to handle packet delays, loading states, and race conditions exactly as a real user would experience.

The Code (Python + Playwright)

We connect directly to the browser's low-level debugger to inject lag.

tests/network_chaos.py
from playwright.sync_api import Page, expect

def test_slow_network_handling(page: Page):
    # 1. Connect to Chrome DevTools Protocol (CDP)
    client = page.context.new_cdp_session(page)
    
    # 2. 🧨 CHAOS: Emulate "Bad 3G"
    # Latency: 2000ms (2 seconds)
    # Throughput: 50kb/s (Very slow)
    client.send("Network.emulateNetworkConditions", {
        "offline": False,
        "latency": 2000, 
        "downloadThroughput": 50 * 1024,
        "uploadThroughput": 50 * 1024
    })

    page.goto("/search")
    
    # 3. Trigger the slow action
    page.fill("#search-box", "Playwright")
    page.click("#search-btn")

    # 4. Resilience Assertion
    # Does the app disable the button to prevent double-clicks?
    expect(page.locator("#search-btn")).to_be_disabled()
    
    # Does the spinner appear immediately?
    expect(page.locator(".loading-spinner")).to_be_visible()

The Limitation of Code-Based Throttling

This script is perfect for automated CI pipelines in Chrome. But what if you need to debug a Native iOS App? Or test how your Android app handles a connection drop while running on a physical device in your hand?

You can't attach Playwright to a real iPhone. That's where you need a System-Level Proxy.

Skip the Python setup

Debuggo lets you simulate "Subway Mode" (2s latency) on any device—iPhone, Android, or Laptop—in one click.

Start Visual Throttling

No credit card required

Why this matters: This test proves your UI provides feedback. If a user clicks a button and waits 2 seconds with no visual feedback, they will click it again, potentially charging their credit card twice. Slow networks don't just annoy users; they cause them to panic. Learn how latency triggers duplicate transactions in our guide: The "Rage Click": Testing Idempotency.