Skip to content

E2E Testing Guide

This guide covers end-to-end testing for the Teams application using Playwright.

Table of Contents


Overview

The E2E test suite uses Playwright 1.58.2 to test complete user workflows. Locally, tests run against all three browsers (Chromium, Firefox, WebKit). In CI, only Chromium is tested for speed (ADR-0015).

What We Test

  • User workflows: Login, navigation, thread management
  • Real-time collaboration: Multi-user comments, shared drafts (Yjs/WebSocket)
  • App Suite integration: Mail API, sessions, accounts
  • UI interactions: Assignment, status changes, tags, comments
  • Deep linking: URL persistence, page reloads

Test Coverage

Feature AreaTest FilesKey Scenarios
Provisioningprovisioning.spec.jsUser setup, login, email provisioning
Navigationinbox_list.spec.js, deep_links.spec.jsFolder switching, URL persistence
Thread Managementassignee.spec.js, status.spec.jsAssign/unassign, status updates
Collaborationcomments.spec.js, categories.spec.jsComments, categories
Emailreply.spec.js, mail-detail.spec.jsShared drafts, replies, rendering
Multi-usermultiuser.spec.jsReal-time synchronization
Onboardingtour-view.spec.jsGuided tour workflow

Total: 11 test specs, ~803 lines of test code


Quick Start

# 1. Install dependencies
pnpm install

# 2. Install Playwright browsers (first time only)
npx playwright install

# 3. Configure environment (see Environment Setup below)
# Create e2e/.env with your settings (see e2e/.env.defaults for reference)
# Example:
echo "LAUNCH_URL=https://localhost:5173/
E2E_ADMIN_PW=your-password" > e2e/.env

# 4. Run tests
pnpm e2e

# 5. View HTML report
npx playwright show-report

Environment Setup

Environment Variables

The E2E tests use environment variables loaded from e2e/.env (overrides e2e/.env.defaults).

Default values are provided in e2e/.env.defaults. To customize, create e2e/.env with only the values you need to override:

# e2e/.env - Only override what you need
LAUNCH_URL=https://localhost:5173/
E2E_ADMIN_PW=your-admin-password

Available variables (see e2e/.env.defaults for full reference):

# Target Application URL
LAUNCH_URL=https://localhost:5173/
# OR for remote testing:
# LAUNCH_URL=https://teams-reply.dev.oxui.de/

# Admin Credentials for Provisioning
E2E_ADMIN_USER=oxadmin        # Default: oxadmin
E2E_ADMIN_PW=your-password    # Required: no default

# Mail Domain (for provisioned users)
MX_DOMAIN=box.ox.io           # Default: box.ox.io

# Browser Mode
HEADLESS=false                # Default: false (set to true for headless)

Local Development Setup

For local testing against https://localhost:5173:

  1. Start the backend:

    pnpm dev  # Runs on http://127.0.0.1:8080
  2. Start the UI dev server (separate terminal):

    pnpm vite dev  # Runs on https://localhost:5173
  3. Create e2e/.env with your settings:

    # e2e/.env
    LAUNCH_URL=https://localhost:5173/
    E2E_ADMIN_PW=your-admin-password
  4. Run tests:

    pnpm e2e

Remote Environment Testing

To test against a deployed environment:

LAUNCH_URL=https://teams-reply.dev.oxui.de/ pnpm e2e

Note: The provisioning fixture will create test users via SOAP API using the admin credentials.


Running Tests

Basic Commands

# Run all tests across all browsers
pnpm e2e

# Run tests in headed mode (see browser)
pnpm e2e --headed

# Run tests in a specific browser
pnpm e2e --project=chromium
pnpm e2e --project=firefox
pnpm e2e --project=webkit

# Run a specific test file
pnpm e2e e2e/tests/comments.spec.js

# Run tests matching a pattern
pnpm e2e --grep "assign to me"

# Run in debug mode
pnpm e2e --debug

# Run with UI mode (interactive)
npx playwright test --ui

Advanced Options

# Run tests sequentially (no parallelization)
pnpm e2e --workers=1

# Run with retries
pnpm e2e --retries=2

# Generate trace files for debugging
pnpm e2e --trace=on

# Run tests with specific timeout
pnpm e2e --timeout=60000  # 60 seconds

# Update snapshots (if using visual regression)
pnpm e2e --update-snapshots

Viewing Reports

# Open the last HTML report
npx playwright show-report

# Open a specific report
npx playwright show-report playwright-report/

# View trace files
npx playwright show-trace test-results/path-to-trace.zip

Test Architecture

Directory Structure

e2e/
├── fixtures/
│   ├── base.ts           # Main fixture exports
│   ├── provisioning.ts   # User provisioning via SOAP
│   └── mail.ts           # Email sending fixture
├── tests/
│   ├── provisioning.spec.js
│   ├── inbox_list.spec.js
│   ├── assignee.spec.js
│   ├── status.spec.js
│   ├── comments.spec.js
│   ├── categories.spec.js
│   ├── reply.spec.js
│   ├── multiuser.spec.js
│   ├── mail-detail.spec.js
│   ├── deep_links.spec.js
│   └── tour-view.spec.js
├── .env                  # Environment variables
└── output/              # Test artifacts (screenshots, traces)

Fixture System

The test suite uses custom Playwright fixtures for setup and teardown. See fixture files in e2e/fixtures/:

  • provisioning.ts - Creates test users/contexts via SOAP API (worker-scoped)
  • mail.ts - Send test emails via App Suite Mail API
  • base.ts - Combines fixtures and extends Playwright test

Available Fixtures:

test('my test', async ({
  page,                  // Playwright page
  currentUser,           // First provisioned user
  users,                 // All 5 provisioned users
  sendMail,              // Email sending function
  browser,               // Browser instance (for multi-user tests)
  context                // Browser context
}) => {
  // Your test code
})

Test Lifecycle

1. Worker starts
   ↓
2. Provisioning fixture runs (worker-scoped)
   - Creates context via SOAP
   - Provisions 5 users with random names
   - Creates secondary accounts
   - Saves authentication state
   ↓
3. Tests run (reuse provisioned users)
   - Load storage state (already logged in)
   - Send test emails
   - Interact with UI
   - Verify behavior
   ↓
4. Worker finishes
   - Cleanup: Delete context and users

Writing Tests

Core Patterns

Basic test structure:

  • Import fixtures: import { expect, test } from '../fixtures/base.js'
  • Use test.describe() to group related tests
  • Set up with test.beforeEach() for common navigation
  • Arrange-Act-Assert pattern in test body

Key fixtures:

  • page - Playwright page object
  • currentUser - Authenticated user with secondary account
  • sendMail - Function to send test emails
  • users - Array of 5 provisioned users for multi-user tests
  • browser - Browser instance for creating additional contexts

Examples: See existing test files in e2e/tests/:

  • comments.spec.js - Basic test structure with sendMail
  • assignee.spec.js - Using test steps for complex flows
  • multiuser.spec.js - Multi-user collaboration patterns
  • provisioning.spec.js - Simplest test structure

Test Data

Use Faker for randomization:

import { faker } from '@faker-js/faker'
const subject = faker.word.words(5)

Why? Prevents test pollution and ensures test independence.

Multi-User Testing

Create additional browser contexts for real-time collaboration tests:

const user2Context = await browser.newContext({
  storageState: users[1].storageState
})
const user2Page = await user2Context.newPage()

See e2e/tests/multiuser.spec.js for complete examples.

Browser Configuration

By default, tests run against Chromium only (ADR-0015).

Locally all three browsers are tested. CI runs Chromium only (ADR-0015).

To run a specific browser locally:

npx playwright test --project=chromium

Debugging

Quick debugging commands:

pnpm e2e --debug              # Playwright Inspector (step through tests)
pnpm e2e --headed             # Watch tests execute
pnpm e2e --headed --slow-mo=1000  # Slow down execution
pnpm e2e --trace=on           # Capture traces for failed tests

View traces:

npx playwright show-trace test-results/path-to-trace.zip

Add breakpoints in tests:

await page.pause()  // Opens Playwright Inspector

Screenshots: Automatically captured on failure in test-results/

For detailed troubleshooting: See E2E Troubleshooting Guide


CI/CD Integration

Tests run automatically on merge requests via GitLab CI (.gitlab-ci.yml):

  • 3 parallel workers with browser sharding
  • 2 retries on failure
  • Tests against deployed review environment
  • HTML reports published as artifacts

View reports: GitLab pipeline → "playwright" job → Artifacts → "playwright-report/index.html"

Simulate CI locally:

CI=true pnpm e2e --workers=1 --retries=2

Best Practices Quick Reference

  1. Use role-based selectors: getByRole() over CSS selectors
  2. Randomize test data: Use Faker for independence
  3. Clean isolation: Each test independent, use test.beforeEach()
  4. Explicit waits: await expect().toBeVisible() not waitForTimeout()
  5. Test steps: Use test.step() for complex flows
  6. Browser differences: Document skips with test.fixme()
  7. Real-time sync: Test WebSocket/Yjs with multi-user scenarios
  8. Descriptive names: Describe behavior, not implementation
  9. Leverage fixtures: Use sendMail, currentUser, users

For troubleshooting: See E2E Troubleshooting Guide.


Playwright Test Agents

This project uses specialized Playwright agents (via Claude Code's Task tool) for test development:

  • Test Planner: Creates test specifications in docs/development/testing/specs/
  • Test Generator: Generates test files in e2e/tests/ from specifications
  • Test Healer: Debugs and fixes failing tests

Workflow: Plan → Generate → Maintain

Test specifications: See Test Specs Overview for all test spec documents.


Contributing

Adding New Tests

Recommended: Use Playwright Test Agents (Plan → Generate → Verify)

Manual process:

  1. Create test spec in docs/development/testing/specs/
  2. Follow existing test patterns in e2e/tests/
  3. Use fixtures (currentUser, sendMail, users)
  4. Randomize test data with Faker
  5. Use role-based selectors
  6. Document browser-specific skips

Additional Resources