Skip to content
On this page
[Test types]

End-to-end testing

An end-to-end test drives a real browser through a whole user journey, so the front end, the API and the database are all checked at once. In xtest you describe the journey in plain English and a test agent carries it out. The Playwright below is for the same journeys written by hand, in your own project.

Examples in Playwright

These run with npx playwright test in your own project. xtest does not execute scripts on its servers.

A journey from search to order history

javascript
// E2E test for a complete e-commerce flow
const { test, expect } = require('@playwright/test');

test.describe('E2E: Complete Shopping Journey', () => {
  test('user can browse, purchase, and track order', async ({ page }) => {
    // Step 1: Browse products
    await page.goto('/products');
    await page.fill('[data-testid="search"]', 'laptop');
    await page.click('[data-testid="search-btn"]');

    // Step 2: Select product
    await page.click('.product-card:first-child');
    await expect(page.locator('h1')).toContainText('laptop');

    // Step 3: Add to cart
    await page.click('[data-testid="add-to-cart"]');
    await expect(page.locator('.cart-notification')).toBeVisible();

    // Step 4: Checkout process
    await page.click('[data-testid="cart-icon"]');
    await page.click('[data-testid="checkout-btn"]');

    // Step 5: Fill shipping information
    await page.fill('#shipping-name', 'John Doe');
    await page.fill('#shipping-address', '123 Main St');
    await page.fill('#shipping-city', 'Anytown');
    await page.selectOption('#shipping-state', 'CA');

    // Step 6: Payment with a test card
    await page.fill('#card-number', '4111111111111111');
    await page.fill('#card-expiry', '12/25');
    await page.fill('#card-cvc', '123');

    // Step 7: Complete order
    await page.click('[data-testid="place-order"]');

    // Step 8: Verify order confirmation
    await expect(page).toHaveURL(/.*order-confirmation.*/);
    await expect(page.locator('.order-number')).toBeVisible();

    // Step 9: Check order in profile
    await page.click('[data-testid="profile-menu"]');
    await page.click('[data-testid="order-history"]');
    await expect(page.locator('.order-item:first-child')).toBeVisible();
  });
});

What keeps them working

Pick journeys, not pages

Sign-up, checkout and the one flow that loses money when it breaks. Leave the rest to smaller tests.

Give elements a test id

A data-testid survives a redesign; a CSS class beside it usually does not.

Wait for state, not time

Assert that the element is there. A sleep passes on a fast day and fails on a slow one.

Keep them few

An end-to-end suite that takes an hour stops being run. Cover the detail in unit and integration tests.

[Academy courses]