|
| 1 | +--- |
| 2 | +name: tests |
| 3 | +description: E2E test conventions for OpenProject integration tests. Use when writing, modifying, or reviewing Playwright tests, page objects, utilities, or locators in this repository. |
| 4 | +--- |
| 5 | + |
| 6 | +# OpenProject E2E Tests Skill |
| 7 | + |
| 8 | +## Architecture Overview |
| 9 | + |
| 10 | +- `tests/`: Playwright spec files (integration flows across OpenProject, Nextcloud, Keycloak). |
| 11 | +- `pageobjects/`: Page Object Model classes wrapping UI interactions. |
| 12 | +- `locators/`: JSON locator definitions for each product (`openproject.json`, `nextcloud.json`, `keycloak.json`). |
| 13 | +- `utils/`: Shared helpers (config, env/hosts, API clients, error handling, logging, version detection, test helpers). |
| 14 | +- `global-setup.ts`: Pre-test setup (Kubernetes setup-job wait, version detection, env var enrichment). |
| 15 | +- `playwright.config.ts`: Playwright runner config (headless by default, workers, retries, etc.). |
| 16 | + |
| 17 | +Page object inheritance: |
| 18 | +- `BasePage` → domain base pages (`OpenProjectBasePage`, `NextcloudBasePage`, `KeycloakBasePage`) → concrete pages (Login, Home, Admin, etc.). |
| 19 | + |
| 20 | +## Locator Rules |
| 21 | + |
| 22 | +- Never put selectors directly into test code; always use locator rules and JSON files in `locators/`. |
| 23 | +- Locator file structure: |
| 24 | + |
| 25 | +```markdown |
| 26 | +{ |
| 27 | + "url": "https://example/", |
| 28 | + "selectors": { |
| 29 | + "loginButton": { "by": "getByRole", "value": { "role": "button", "name": "Login" } } |
| 30 | + } |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +- Prefer semantic locators: `getByRole`, `getByLabel`, `getByText`, `getByPlaceholder`, `getByTitle`. |
| 35 | +- Use `getByTestId` when `data-testid` attributes are available. |
| 36 | +- Use `locator` (CSS/XPath) only as a last resort when semantic selectors are not possible. |
| 37 | +- Keep locator keys descriptive and stable (e.g., `usernameInput`, `projectSettingsButton`, `storageCreationSuccessMessage`). |
| 38 | +- See `utils/locators_guide.md` for detailed locator patterns and supported `by` values. |
| 39 | + |
| 40 | +## Page Object Conventions |
| 41 | + |
| 42 | +- When adding a new test, first check if an existing page object can be reused or extended before creating a new one. |
| 43 | +- All page objects must: |
| 44 | + - Extend the appropriate domain base page (`OpenProjectBasePage`, `NextcloudBasePage`, `KeycloakBasePage`) or `BasePage`. |
| 45 | + - Load locators via the base constructor using the correct locator JSON file. |
| 46 | + - Use `getLocator(key)` to resolve selectors; do not hardcode selectors inside page objects. |
| 47 | +- Domain base pages: |
| 48 | + - `OpenProjectBasePage` uses `locators/openproject.json`. |
| 49 | + - `NextcloudBasePage` uses `locators/nextcloud.json`. |
| 50 | + - `KeycloakBasePage` uses `locators/keycloak.json`. |
| 51 | +- Export page objects via `index.ts` barrel files per domain for consistent imports. |
| 52 | +- Encapsulate complex flows in page methods rather than duplicating sequences in tests. |
| 53 | + |
| 54 | +## Error Handling Standards |
| 55 | + |
| 56 | +- Always use typed catches: |
| 57 | + |
| 58 | +```ts |
| 59 | +try { |
| 60 | + // ... |
| 61 | +} catch (error: unknown) { |
| 62 | + logError("Something failed", getErrorMessage(error)); |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +- Never use `catch (error: any)` or untyped `catch (error)` in new or modified code. |
| 67 | +- Use `getErrorMessage(error)` from `utils/error-utils.ts` to safely extract an error message from unknown values. |
| 68 | +- Avoid truly silent failures: |
| 69 | + - For expected fallbacks, at least log with `logDebug` or `logWarn`. |
| 70 | + - For unexpected failures, use `logError` and either rethrow or fail fast depending on context. |
| 71 | + |
| 72 | +## Logging Standards |
| 73 | + |
| 74 | +- Use the central logger from `utils/logger.ts`: |
| 75 | + - `logDebug(...)` |
| 76 | + - `logInfo(...)` |
| 77 | + - `logWarn(...)` |
| 78 | + - `logError(...)` |
| 79 | +- Do not use `console.log`, `console.warn`, or `console.error` directly in tests, page objects, or utils. |
| 80 | +- Log level is controlled by `E2E_LOG_LEVEL` (`debug`, `info`, `warn`, `error`) and defaults to `info`. |
| 81 | + - Use `logDebug` for verbose troubleshooting. |
| 82 | + - Use `logInfo` for high-level lifecycle information (start/end of major flows). |
| 83 | + - Use `logWarn` for recoverable issues and fallbacks. |
| 84 | + - Use `logError` for failures that should normally fail the run or require attention. |
| 85 | + |
| 86 | +## Environment and Configuration |
| 87 | + |
| 88 | +- Always resolve environment name and hosts via `utils/env-hosts.ts`: |
| 89 | + - `resolveEnvName()` chooses the environment (`local`, `edge`, `stage`, etc.) based on `E2E_ENV` or `ENV` (default: `local`). |
| 90 | + - `resolveHosts(envName?)` returns OpenProject, Nextcloud, and Keycloak hosts using env vars with per-env defaults. |
| 91 | +- Do not duplicate host or environment resolution logic inside tests or helpers; always call the shared utilities. |
| 92 | +- Configuration is loaded once in `utils/config.ts` and exposed as `testConfig`: |
| 93 | + - Service URLs and versions. |
| 94 | + - Setup method and environment name. |
| 95 | + - Any additional test-level configuration. |
| 96 | +- `global-setup.ts`: |
| 97 | + - Optionally waits for Kubernetes `setup-job` completion when `SETUP_JOB_CHECK=true` (uses `utils/pod-waiter.ts`). |
| 98 | + - Runs `detectAllVersions()` from `utils/version-detect.ts` to populate version-related env vars (OpenProject, Nextcloud, Keycloak, etc.) if not already set. |
| 99 | + |
| 100 | +## Type Safety |
| 101 | + |
| 102 | +- Prefer explicit TypeScript interfaces and types for: |
| 103 | + - API responses (e.g., OpenProject v3, Nextcloud capabilities and status endpoints, Keycloak server info). |
| 104 | + - Config structures and helper return types. |
| 105 | +- Avoid `Record<string, any>` and other untyped shapes in new or refactored code. |
| 106 | +- Keep interfaces close to their usage (e.g., in `utils/version-detect.ts` for version APIs). |
| 107 | + |
| 108 | +## Test Helpers and Reuse |
| 109 | + |
| 110 | +- Use functions for repetitive actions so they can be reused later rather than copied into each spec. |
| 111 | +- Shared helpers live primarily in: |
| 112 | + - `utils/test-helpers.ts` for high-level flows (e.g., `ensureProjectExists`, `ensureProjectHasNextcloudStorage`, `ensureDemoProjectCopyViaUi`). |
| 113 | + - `utils/openproject-api.ts` for direct API interactions with OpenProject (projects, users, storages). |
| 114 | +- When adding new cross-test flows: |
| 115 | + - First, see if existing helpers can be extended. |
| 116 | + - If needed, create a new helper function with a clear name and parameters. |
| 117 | +- After UI actions that should succeed, verify the expected UI feedback: |
| 118 | + - Example: after adding Nextcloud storage from OpenProject, wait for the success banner (`storageCreationSuccessMessage` locator, text `"Successful creation."`). |
| 119 | + |
| 120 | +## Running Tests |
| 121 | + |
| 122 | +- Tests run in headless mode by default (see `playwright.config.ts`). |
| 123 | +- To run in headed mode, use Playwright’s native CLI flags, e.g.: |
| 124 | + - `npx playwright test --headed` |
| 125 | +- Default worker configuration: |
| 126 | + - Single worker (`workers: 1`) to keep tests predictable and avoid cross-test interference. |
| 127 | +- Common commands: |
| 128 | + - Run tests: `npx playwright test` |
| 129 | + - Run tests headed: `npx playwright test --headed` |
| 130 | + - Run tests and open report: `npx playwright test && npx playwright show-report` |
| 131 | + |
| 132 | +## Self-Improvement Directive |
| 133 | + |
| 134 | +- After completing significant refactoring, introducing new patterns, or making architectural changes to this E2E codebase: |
| 135 | + - Update this `SKILL.md` to reflect the new conventions, helpers, and standards. |
| 136 | + - Keep the file concise and focused on project-specific knowledge that future sessions should follow by default. |
| 137 | + |
0 commit comments