e2e-tests/playwright/CLAUDE.OPTIONAL.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the Playwright E2E testing suite for Mattermost. It contains end-to-end tests for validating the Mattermost web application functionality using the Playwright testing framework.
# Install npm packages
npm i
# Install browser binaries (if prompted)
npx playwright install
# Run a specific test across all browsers (Chrome, Firefox, iPad)
npm run test -- <test-name>
# Run a specific test for a specific browser
npm run test -- <test-name> --project=chrome
npm run test -- <test-name> --project=firefox
npm run test -- <test-name> --project=ipad
# Run all tests (including visual tests)
npm run test
# Run CI tests (excludes visual tests, runs only in Chrome)
npm run test:ci
# Run tests with UI mode
npm run playwright-ui
# Run tests with slow-motion to debug
npm run test:slomo
# Run visual tests
npm run test -- visual
# Update visual test snapshots
npm run test:update-snapshots
# Visual testing with Percy
npm run percy:docker
# Build the project
npm run build
# Watch mode for development
npm run build:watch
# Type checking
npm run tsc
# Linting
npm run lint
# Format code
npm run prettier:fix
# Verify test documentation format
npm run lint:test-docs
# Run all checks (lint, prettier, typescript, test docs)
npm run check
# Clean the project
npm run clean
# Show test report
npm run show-report
lib/ Directory: Contains the shared library (@mattermost/playwright-lib) that provides:
specs/ Directory: Contains the actual test files organized by type:
functional/ - Functional tests for various featuresvisual/ - Visual regression testsaccessibility/ - Accessibility testsclient/ - Client API testsTest Fixtures: The main test fixture (pw) provides:
Page Object Model: UI abstractions are organized in:
lib/src/ui/pages/ - Page objects (Login, Channels, etc.)lib/src/ui/components/ - Component objects (Posts, Menus, etc.)Tests typically follow this pattern:
pw.initSetup()pw.testBrowser.login()Visual tests also:
pw.hideDynamicChannelsContent()pw.matchSnapshot()Tests can be configured through environment variables:
PW_BASE_URL - Mattermost server URL (default: http://localhost:8065)PW_ADMIN_USERNAME - Admin username (default: sysadmin)PW_ADMIN_PASSWORD - Admin password (default: Sys@dmin-sample1)PW_HEADLESS - Run tests headless (default: true)PW_SNAPSHOT_ENABLE - Enable snapshot testing (default: false)PW_SLOWMO - Add delay between actions in ms (default: 0)PW_WORKERS - Number of parallel workers (default: 1)PERCY_TOKEN - Authentication token for Percy visual testing service (required for Percy tests)Before running tests, a Mattermost server must be available. Two options:
Run from source:
cd server && make run
Run using Docker (recommended for testing):
# Configure environment in e2e-tests/.ci/env
cd e2e-tests && TEST=playwright make
Page Object Pattern: Always use page/component objects from the library. No static UI selectors should be in test files.
Locator Priority: Follow the Playwright recommended locator strategy (see Playwright Locators Quick Guide). Use locators in this priority order:
getByRole() - Preferred. Locates by accessibility role and accessible name (e.g., getByRole('button', {name: 'Submit'})).getByText() - Locates by visible text content.getByLabel() - Locates form controls by their associated label text.getByPlaceholder() - Locates inputs by placeholder text.getByAltText() - Locates elements (usually images) by alt text.getByTitle() - Locates by the title attribute.getByTestId() - Last resort. Locates by data-testid attribute..class, #id), XPath, and raw locator() calls unless none of the above locators can identify the element.{exact: true} when the accessible name might partially match other elements (e.g., getByRole('button', {name: 'Invite', exact: true})).Visual Testing: For visual tests:
specs/visual/ directory@visual tag in the test tags arraypw.hideDynamicChannelsContent() to hide dynamic elements that could cause flaky testsnpm run test:update-snapshots only from within the Docker containerPERCY_TOKEN environment variable must be setTest Title Validation with Claude Code: When using Claude:
claude spec/path/to/file.spec.ts to check your test filecreates scheduled message from channel and posts at scheduled timeTest Structure:
"creates scheduled message from channel and posts at scheduled time""edits scheduled message content while preserving send date""reschedules message to a future date from scheduled posts page""deletes scheduled message from scheduled posts page""converts draft message to scheduled message"MM-T\d+) in test titles are optional for new tests
# Action and * Verification comment pattern{tag: '@feature_name'}Test Documentation Format:
/**
* @objective Clear description of what the test verifies
*
* @precondition
* Special setup or conditions required for the test
* Note: Only include preconditions that are not part of the default setup.
* Standard conditions like "a test server is running" should be omitted.
*/
test('MM-T1234 descriptive test title', {tag: '@feature_tag'}, async ({pw}) => {
// Test implementation
});
@precondition tag entirely:
/**
* @objective Clear description of what the test verifies
*/
test('descriptive test title', {tag: '@feature_tag'}, async ({pw}) => {
// Test implementation
});
/**
* @objective Clear description of what the test verifies
*/
test('descriptive test title', {tag: '@feature_tag'}, async ({pw}) => {
// Test implementation
});
// # descriptive action - Comments that describe steps being taken (e.g., // # Initialize user and login)// * descriptive verification - Comments that describe assertions/checks (e.g., // * Verify message appears in channel)Browser Compatibility:
test.skip() for browser-specific limitationsTest Documentation Linting:
npm run lint:test-docs to verify all spec files follow the documentation formatnpm run check commandspecs/functional/channels/scheduled_messages/scheduled_messages.spec.ts