|

Day 18: Performance Testing Basics — Measuring What Matters

This is Day 18 of the 21-Day Playwright with TypeScript Challenge. One lesson per day. Zero to production-ready in 3 weeks.

🎭 Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy.


Playwright is not a load testing tool. But it can measure page load times, Core Web Vitals, and response latency — enough to catch performance regressions before they ship.

Contents

Response Time Assertions

test('homepage loads under 3 seconds', async ({ page }) => {
  const start = Date.now();
  await page.goto('/', { waitUntil: 'domcontentloaded' });
  const loadTime = Date.now() - start;
  expect(loadTime).toBeLessThan(3000);
});

test('API responds under 500ms', async ({ request }) => {
  const start = Date.now();
  const response = await request.get('/api/products');
  const duration = Date.now() - start;
  expect(duration).toBeLessThan(500);
  expect(response.ok()).toBeTruthy();
});

Core Web Vitals

test('measure LCP and CLS', async ({ page }) => {
  await page.goto('/');
  
  const lcp = await page.evaluate(() => {
    return new Promise(resolve => {
      new PerformanceObserver(list => {
        const entries = list.getEntries();
        resolve(entries[entries.length - 1].startTime);
      }).observe({ type: 'largest-contentful-paint', buffered: true });
    });
  });
  
  expect(lcp).toBeLessThan(2500); // Good LCP < 2.5s
});

🚀 Level Up Your Playwright

From locators to CI pipelines — build a production-grade Playwright + TypeScript framework step by step.

Network Throttling

test('works on slow 3G', async ({ page }) => {
  const client = await page.context().newCDPSession(page);
  await client.send('Network.emulateNetworkConditions', {
    offline: false,
    downloadThroughput: 500 * 1024 / 8,  // 500 Kbps
    uploadThroughput: 500 * 1024 / 8,
    latency: 400,  // 400ms
  });
  
  await page.goto('/');
  await expect(page.getByText('Welcome')).toBeVisible({ timeout: 15000 });
});

When Playwright Perf Is Enough vs Dedicated Tools

Use CaseTool
Page load time assertionsPlaywright
Core Web Vitals checkPlaywright + Lighthouse
API response SLAPlaywright
100+ concurrent usersk6 or JMeter
Stress/spike testingk6 or Gatling

Tomorrow (Day 19): Advanced patterns — retry, tags, parameterization, hooks.

🎓 Master Playwright End to End

Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.