Modern QA2026Playwright Synthetic Monitor Script — tiles
Log inJoin
45 / 67 · 06 Observability-Driven Testing · Synthetic Monitoring← prev⊞ allnext →☰ Read as one page

7.3Playwright Synthetic Monitor Script

// synthetic/checkout-flow.spec.ts
// Runs every 5 minutes against production
import { test, expect } from '@playwright/test';

test.describe('Production Checkout Flow', () => {
  test.setTimeout(30_000); // 30s hard timeout for synthetic tests

  test('complete purchase of a test product', async ({ page }) => {
    // Step 1: Navigate and verify homepage
    const startTime = Date.now();
    await page.goto('https://store.example.com');
    await expect(page.locator('h1')).toContainText('Welcome');

    const homepageLoadTime = Date.now() - startTime;
    console.log(`METRIC homepage_load_ms=${homepageLoadTime}`);

    // Step 2: Search for test product
    await page.fill('[data-testid="search-input"]', 'synthetic-test-product');
    await page.click('[data-testid="search-button"]');
    await expect(page.locator('[data-testid="search-results"]')).toBeVisible();

    // Step 3: Add to cart
    await page.click(
      '[data-testid="product-card"]:first-child [data-testid="add-to-cart"]'
    );
    await expect(page.locator('[data-testid="cart-count"]')).toHaveText('1');

    // Step 4: Begin checkout (using test payment method)
    await page.click('[data-testid="cart-icon"]');
    await page.click('[data-testid="checkout-button"]');

    // Use test payment method that does not charge
    await page.fill('[data-testid="card-number"]', '4242424242424242');
    await page.fill('[data-testid="card-expiry"]', '12/28');
    await page.fill('[data-testid="card-cvc"]', '123');

    await page.click('[data-testid="place-order"]');

    // Step 5: Verify order confirmation
    await expect(page.locator('[data-testid="order-confirmation"]')).toBeVisible({
      timeout: 15_000,
    });
    await expect(page.locator('[data-testid="order-id"]')).toBeVisible();

    const totalFlowTime = Date.now() - startTime;
    console.log(`METRIC checkout_flow_total_ms=${totalFlowTime}`);

    // Assert performance budget
    expect(totalFlowTime).toBeLessThan(15_000);
  });
});