e2e/README.md
This guide provides comprehensive information for writing and maintaining end-to-end tests for Super Productivity using Playwright.
Our E2E tests are built with Playwright and follow the Page Object Model (POM) pattern for maintainability and reusability. Tests are organized by feature and use shared fixtures for common setup.
# Run all tests
npm run e2e
# Run tests in UI mode (interactive)
npm run e2e:ui
# Run a single test file with detailed output
npm run e2e:file tests/task-basic/task-crud.spec.ts
# Run tests in headed mode (see browser)
npm run e2e:headed
# Run tests in debug mode
npm run e2e:debug
# Show test report
npm run e2e:show-report
# Run WebDAV tests (starts Docker container)
npm run e2e:webdav
e2e/
├── constants/ # Shared selectors and constants
│ └── selectors.ts # Centralized CSS selectors
├── fixtures/ # Test fixtures and setup
│ └── test.fixture.ts # Custom test fixtures with page objects
├── helpers/ # Test helper functions
│ └── plugin-test.helpers.ts
├── pages/ # Page Object Models
│ ├── base.page.ts # Base page with common methods
│ ├── work-view.page.ts
│ ├── project.page.ts
│ ├── task.page.ts
│ ├── settings.page.ts
│ ├── dialog.page.ts
│ ├── planner.page.ts
│ ├── schedule.page.ts
│ ├── side-nav.page.ts
│ ├── sync.page.ts
│ ├── tag.page.ts
│ └── note.page.ts
├── tests/ # Test specifications
│ ├── task-basic/
│ ├── project/
│ ├── planner/
│ └── ...
├── utils/ # Utility functions
│ ├── waits.ts # Wait helpers
│ └── sync-helpers.ts
├── playwright.config.ts
└── global-setup.ts
Page Objects encapsulate interactions with specific pages or components. All page objects extend BasePage and receive a page and optional testPrefix.
base.page.ts)Base class for all page objects. Provides common functionality:
class BasePage {
async addTask(taskName: string): Promise<void>;
// Adds a task with automatic test prefix
}
Example:
await workViewPage.addTask('My Task');
// Creates task with name "W0-P0-My Task" (prefixed for isolation)
work-view.page.ts)Interactions with the main work view:
class WorkViewPage extends BasePage {
async waitForTaskList(): Promise<void>;
async addSubTask(task: Locator, subTaskName: string): Promise<void>;
}
Example:
await workViewPage.waitForTaskList();
await workViewPage.addTask('Parent Task');
const task = page.locator('task').first();
await workViewPage.addSubTask(task, 'Child Task');
task.page.ts)Task-specific operations:
class TaskPage extends BasePage {
getTask(index: number): Locator;
getTaskByText(text: string): Locator;
async markTaskAsDone(task: Locator): Promise<void>;
async editTaskTitle(task: Locator, newTitle: string): Promise<void>;
async openTaskDetail(task: Locator): Promise<void>;
async getTaskCount(): Promise<number>;
async isTaskDone(task: Locator): Promise<boolean>;
getDoneTasks(): Locator;
getUndoneTasks(): Locator;
async waitForTaskWithText(text: string): Promise<Locator>;
async taskHasTag(task: Locator, tagName: string): Promise<boolean>;
}
Example:
const task = taskPage.getTask(1); // First task
await taskPage.markTaskAsDone(task);
await expect(taskPage.getDoneTasks()).toHaveCount(1);
project.page.ts)Project management:
class ProjectPage extends BasePage {
async createProject(projectName: string): Promise<void>;
async navigateToProjectByName(projectName: string): Promise<void>;
async createAndGoToTestProject(): Promise<void>;
async addNote(noteContent: string): Promise<void>;
async archiveDoneTasks(): Promise<void>;
}
Example:
await projectPage.createProject('My Project');
await projectPage.navigateToProjectByName('My Project');
await projectPage.addNote('Project notes here');
settings.page.ts)Settings and configuration:
class SettingsPage extends BasePage {
async navigateToSettings(): Promise<void>;
async expandSection(sectionSelector: string): Promise<void>;
async expandPluginSection(): Promise<void>;
async navigateToPluginSettings(): Promise<void>;
async enablePlugin(pluginName: string): Promise<boolean>;
async disablePlugin(pluginName: string): Promise<boolean>;
async isPluginEnabled(pluginName: string): Promise<boolean>;
async uploadPlugin(pluginPath: string): Promise<void>;
}
Example:
await settingsPage.navigateToPluginSettings();
await settingsPage.enablePlugin('Test Plugin');
expect(await settingsPage.isPluginEnabled('Test Plugin')).toBeTruthy();
dialog.page.ts)Dialog and modal interactions:
class DialogPage extends BasePage {
async waitForDialog(): Promise<Locator>;
async waitForDialogToClose(): Promise<void>;
async clickDialogButton(buttonText: string): Promise<void>;
async clickSaveButton(): Promise<void>;
async fillDialogInput(selector: string, value: string): Promise<void>;
async fillMarkdownDialog(content: string): Promise<void>;
async saveMarkdownDialog(): Promise<void>;
async editDateTime(dateValue?: string, timeValue?: string): Promise<void>;
}
Example:
await dialogPage.waitForDialog();
await dialogPage.fillDialogInput('input[name="title"]', 'New Title');
await dialogPage.clickSaveButton();
await dialogPage.waitForDialogToClose();
test('should create and edit task', async ({ page, workViewPage, taskPage }) => {
await workViewPage.waitForTaskList();
// Create
await workViewPage.addTask('Test Task');
await expect(taskPage.getAllTasks()).toHaveCount(1);
// Edit
const task = taskPage.getTask(1);
await taskPage.editTaskTitle(task, 'Updated Task');
await expect(taskPage.getTaskTitle(task)).toContainText('Updated Task');
// Mark as done
await taskPage.markTaskAsDone(task);
await expect(taskPage.getDoneTasks()).toHaveCount(1);
});
test('should create project and add tasks', async ({ projectPage, workViewPage }) => {
await projectPage.createAndGoToTestProject();
await workViewPage.addTask('Project Task 1');
await workViewPage.addTask('Project Task 2');
await expect(page.locator('task')).toHaveCount(2);
});
test('should enable plugin', async ({ settingsPage, waitForNav }) => {
await settingsPage.navigateToPluginSettings();
await settingsPage.enablePlugin('My Plugin');
await waitForNav();
expect(await settingsPage.isPluginEnabled('My Plugin')).toBeTruthy();
});
test('should edit date in dialog', async ({ taskPage, dialogPage }) => {
const task = taskPage.getTask(1);
await taskPage.openTaskDetail(task);
const dateInfo = dialogPage.getDateInfo('Created');
await dateInfo.click();
await dialogPage.editDateTime('12/25/2025', undefined);
await dialogPage.clickSaveButton();
});
All selectors are centralized in constants/selectors.ts. Always use these constants instead of hardcoding selectors in tests.
import { cssSelectors } from '../constants/selectors';
const { TASK, TASK_TITLE, TASK_DONE_BTN } = cssSelectors;
// In test:
const task = page.locator(TASK).first();
const title = task.locator(TASK_TITLE);
SIDENAV, NAV_ITEM, SETTINGS_BTNROUTE_WRAPPER, BACKDROP, PAGE_TITLETASK, TASK_TITLE, TASK_DONE_BTN, SUB_TASKADD_TASK_INPUT, ADD_TASK_SUBMITMAT_DIALOG, DIALOG_FULLSCREEN_MARKDOWNPAGE_SETTINGS, PLUGIN_SECTION, PLUGIN_MANAGEMENTPAGE_PROJECT, CREATE_PROJECT_BTN, WORK_CONTEXT_MENULocated in utils/waits.ts, these utilities help handle Angular's async nature.
waitForAngularStability(page, timeout?)Waits for Angular to finish all async operations.
await waitForAngularStability(page);
waitForAppReady(page, options?)Comprehensive wait for app initialization.
await waitForAppReady(page, {
selector: 'task-list',
ensureRoute: true,
routeRegex: /#\/project\/\w+/,
});
waitForStatePersistence(page)Waits for IndexedDB persistence to complete (important before sync operations).
await workViewPage.addTask('Task');
await waitForStatePersistence(page); // Ensure saved to IndexedDB
// Now safe to trigger sync
// e2e/tests/my-feature/my-feature.spec.ts
import { test, expect } from '../../fixtures/test.fixture';
test.describe('My Feature', () => {
test('should do something', async ({ page, workViewPage, taskPage }) => {
// Test code here
});
});
test('my test', async ({ workViewPage, taskPage, dialogPage }) => {
// Wait for page ready
await workViewPage.waitForTaskList();
// Use page objects for interactions
await workViewPage.addTask('Task 1');
const task = taskPage.getTask(1);
await taskPage.markTaskAsDone(task);
// Assertions
await expect(taskPage.getDoneTasks()).toHaveCount(1);
});
// GOOD: Use Angular stability waits
await workViewPage.addTask('Task');
await waitForAngularStability(page);
await expect(page.locator('task')).toBeVisible();
// BAD: Arbitrary timeouts
await page.waitForTimeout(5000); // Avoid unless necessary
import { cssSelectors } from '../../constants/selectors';
const { TASK, TASK_TITLE } = cssSelectors;
const title = page.locator(TASK).first().locator(TASK_TITLE);
constants/selectors.ts// GOOD
await page.getByRole('button', { name: 'Save' }).click();
// LESS GOOD
await page.locator('.save-btn').click();
cssSelectorswaitForAngularStabilityany types - maintain type safetyEach test gets:
W0-P0-, W1-P0-, etc.)This ensures tests don't interfere with each other.
// Use waitFor with explicit conditions
await page.waitForFunction(() => document.querySelectorAll('task').length === 3, {
timeout: 10000,
});
// Use locator assertions (auto-retry)
await expect(page.locator('task')).toHaveCount(3);
// Avoid fixed timeouts
await page.waitForTimeout(1000); // BAD
await waitForAngularStability(page); // GOOD
constants/selectors.tsawait waitForAngularStability(page)await element.waitFor({ state: 'visible' })page.pause() to debug interactivelywaitForAngularStability, waitForAppReadypage.waitForTimeout() - use condition-based waitswaitForStatePersistence before operations that depend on saved state// Pause execution and open Playwright Inspector
await page.pause();
// Take screenshot
await page.screenshot({ path: 'debug.png' });
// Console log page content
console.log(await page.content());
// Get element text for debugging
const text = await page.locator('task').first().textContent();
console.log('Task text:', text);
# Run specific file
npm run e2e:file tests/task-basic/task-crud.spec.ts
# Run in debug mode
npm run e2e:debug
# Run in headed mode to see browser
npm run e2e:headed
import { test, expect } from '../../fixtures/test.fixture';
test.describe('Task CRUD', () => {
test('should create, edit, and delete tasks', async ({
page,
workViewPage,
taskPage,
}) => {
await workViewPage.waitForTaskList();
// Create
await workViewPage.addTask('Task 1');
await workViewPage.addTask('Task 2');
await expect(taskPage.getAllTasks()).toHaveCount(2);
// Edit
const firstTask = taskPage.getTask(1);
await taskPage.editTaskTitle(firstTask, 'Updated Task');
await expect(taskPage.getTaskTitle(firstTask)).toContainText('Updated Task');
// Mark as done
await taskPage.markTaskAsDone(firstTask);
await expect(taskPage.getDoneTasks()).toHaveCount(1);
await expect(taskPage.getUndoneTasks()).toHaveCount(1);
});
});
test('should create project with tasks', async ({
projectPage,
workViewPage,
taskPage,
}) => {
await projectPage.createAndGoToTestProject();
await workViewPage.addTask('Project Task');
await projectPage.addNote('Important notes');
const task = taskPage.getTask(1);
await taskPage.markTaskAsDone(task);
await projectPage.archiveDoneTasks();
await expect(taskPage.getUndoneTasks()).toHaveCount(0);
});
test('should configure plugin', async ({ settingsPage, page }) => {
await settingsPage.navigateToPluginSettings();
const pluginExists = await settingsPage.pluginExists('Test Plugin');
expect(pluginExists).toBeTruthy();
await settingsPage.enablePlugin('Test Plugin');
expect(await settingsPage.isPluginEnabled('Test Plugin')).toBeTruthy();
await settingsPage.navigateBackToWorkView();
await expect(page).toHaveURL(/tag\/TODAY/);
});
e2e/tests/ for examplese2e/pages/ for available methodsconstants/selectors.ts for available selectorsnpm run e2e:debug) for debuggingWhen writing a new test:
tests/ subdirectorytest and expect from fixtures/test.fixture.tsconstants/selectors.tswaitForAngularStability, etc.)