Combining Fixtures, Network, Assertions and CI

Playwright’s real power appears when you combine fixtures, network controls, assertions and CI into cohesive flows. This lesson walks through an end-to-end example that ties these concepts together.

Putting Key Playwright Features Together

Consider a checkout flow that needs authenticated users, seeded cart data, network verification and CI-friendly configuration. You can wire this through fixtures and helpers.

// fixtures/auth-and-cart.ts
import { test as base } from '@playwright/test';

export const test = base.extend({
  authPage: async ({ page }, use) => {
    await page.goto('https://demo.myshop.com/login');
    await page.getByLabel('Email').fill('user@example.com');
    await page.getByLabel('Password').fill('SuperSecret123');
    await page.getByRole('button', { name: 'Sign in' }).click();
    await use(page);
  },
});
// checkout-flow.spec.ts
import { expect } from '@playwright/test';
import { test } from './fixtures/auth-and-cart';

-test('user can complete checkout with verified API calls', async ({ authPage }) => {
+test('user can complete checkout with verified API calls', async ({ authPage }) => {
  const intercepted: string[] = [];

  authPage.on('request', req => {
    if (req.url().includes('/api/checkout')) {
      intercepted.push(req.method());
    }
  });

  await authPage.goto('https://demo.myshop.com/cart');
  await authPage.getByRole('button', { name: 'Checkout' }).click();
  await authPage.getByRole('button', { name: 'Confirm order' }).click();

  await expect(authPage.getByText('Order confirmed')).toBeVisible();
  expect(intercepted).toContain('POST');
});
Note: Fixtures manage setup, locators express intent, network listeners verify integration and assertions encode behaviour; CI ties it all into a repeatable pipeline.
Tip: Start with one or two end-to-end β€œgolden path” flows wired this way, then expand patterns outward.
Warning: Avoid putting all logic into a single mega-test; keep flows focused and rely on shared fixtures and helpers instead.

This composition demonstrates how previous chapters fit together in practical, production-like scenarios.

Common Mistakes

Mistake 1 β€” Treating each Playwright feature in isolation

This misses synergy.

❌ Wrong: Using fixtures without network checks or CI integration.

βœ… Correct: Combine features to build realistic, robust flows.

Mistake 2 β€” Overstuffing a single end-to-end test

This reduces clarity.

❌ Wrong: One massive test that covers every path in the app.

βœ… Correct: Compose smaller tests with shared building blocks.

🧠 Test Yourself

Why is it helpful to combine fixtures, network checks and CI in one flow?