@@ -9,50 +9,108 @@ Run E2E tests with the following configuration:
99## Context
1010
1111- Test files location: ` frontend/e2e/tests/*.pw.ts `
12- - Test results: ` frontend/e2e/test-results/results.json `
12+ - Test results: Individual test directories in ` frontend/e2e/test-results/ `
13+ - ** For EACH failed test** , a directory is created with these files:
14+
15+ ## ALWAYS read these files in this order when debugging failures:
16+
17+ 1 . ** ` failed.json ` ** (in ` test-results/ ` root) - START HERE
18+ - Contains only failed tests with error messages, stack traces, file paths, line numbers
19+ - Much smaller than results.json - only failures
20+
21+ 2 . ** ` error-context.md ` ** (in each failed test directory) - READ THIS SECOND
22+ - ** THIS IS THE MOST VALUABLE FILE** - shows exact page state when test failed
23+ - YAML tree structure of the entire DOM with element states
24+ - Shows which buttons are disabled/enabled
25+ - Shows form field values
26+ - Shows what's visible on the page
27+ - Example: Can see if a button is ` [disabled] ` or a field is empty
28+
29+ 3 . ** Trace files** (if needed for more detail):
30+ - Unzip ` trace.zip ` to get:
31+ - ` 0-trace.trace ` - Every action taken with timestamps and selectors
32+ - ` 0-trace.network ` - Network requests
33+ - Screenshots (jpegs) showing visual state at each step
34+
35+ 4 . ** Full JSON report** : ` results.json ` - contains ALL test results (passed + failed), only use if needed
36+
37+ - ** HTML report** : ` frontend/e2e/playwright-report/ ` - browsable HTML interface (for humans, not programmatic use)
1338- Tests use Playwright with Firefox
1439- The retry logic is built into the test runner (via ` run-with-retry.ts ` )
1540- Tests run against a local Docker environment (API + DB)
1641
1742## Workflow
1843
44+ ** IMPORTANT: Always start by changing to the frontend directory** - the ` .env ` file and dependencies are located there.
45+
19461 . ** Run tests** from the frontend directory:
2047 ``` bash
2148 cd frontend
2249 SKIP_BUNDLE=1 E2E_CONCURRENCY=20 npm run test -- --grep-invert @enterprise --quiet
2350 ```
2451
25- 2 . ** If ANY tests fail (even after automatic retries):**
52+ 2 . ** ALWAYS check for flaky tests after test run completes:**
53+
54+ ** CRITICAL:** Tests that fail initially but pass on retry are FLAKY and MUST be investigated, even if the final result shows all tests passed.
55+
56+ a. Check the test output for any tests that failed on first run (look for the initial failure messages before "Retrying")
57+
58+ b. For EACH test that failed initially (even if it passed on retry):
59+ - Parse the error from the test output:
60+ * Error type (e.g., ` TimeoutError ` , ` AssertionError ` )
61+ * Error message (e.g., ` "waiting for locator('#button') to be visible" ` )
62+ * File path and line number where it failed
63+ * Stack trace showing the call chain
64+ - Read the test file at the failing line number to understand what was being tested
65+ - ** Report these as FLAKY TESTS** - they indicate timing issues, race conditions, or environmental problems
66+ - ** Analyze the root cause** :
67+ * Timeout errors → likely missing waits or race conditions
68+ * Assertion errors → check if value is correct or if timing is off
69+ * Element not found → selector may have changed or element loads slowly
70+
71+ c. ** If ANY tests are still failing after automatic retries:**
72+
73+ For EACH failed test, ** ALWAYS READ TRACES FIRST:**
74+
75+ 1 . ** Read error-context.md** in the failed test directory:
76+ - Shows exact DOM state when test failed
77+ - YAML tree with all elements, their states, and data-test attributes
78+ - Check if expected elements exist and their actual values
79+ - Verify selector is correct by searching for the data-test attribute
2680
27- a. Parse the test output and ` e2e/test-results/results.json ` to identify failures
81+ 2 . ** If error-context.md doesn't show the issue** , unzip and check trace files:
82+ ``` bash
83+ cd frontend/e2e/test-results/< failed-test-directory>
84+ unzip -q trace.zip
85+ grep -i " error\|failed" 0-trace.network # Check for network errors
86+ ```
2887
29- b. For EACH failed test:
30- - Read the test file
31- - Read the error message and stack trace
32- - Analyze the root cause
33- - ** Attempt to fix the issue** if it's one of these:
88+ 3. ** Only after analyzing traces** , read the test file and fix:
89+ - Wrong selector → Update to match actual DOM from error-context.md
3490 - Missing ` data-test` attribute → Add it to the component
35- - Selector changed → Update the test to use the new selector
91+ - Element hidden → Filter for visible elements or wait for visibility
3692 - Missing wait → Add appropriate ` waitFor* ` calls
3793 - Race condition → Add network waits, increase timeouts, or use more specific waits
3894 - Flaky element interaction → Add ` scrollIntoView` or ` waitForVisible` before clicking
3995
40- c . ** After making fixes** , re-run ONLY the failed tests:
96+ d . ** After making fixes** , re-run ONLY the failed tests:
4197 ` ` ` bash
4298 cd frontend
4399 SKIP_BUNDLE=1 E2E_CONCURRENCY=1 npm run test -- tests/flag-tests.pw.ts tests/invite-test.pw.ts
44100 ` ` `
45101 - Use concurrency=1 to avoid race conditions
46102 - Only run the specific test files that failed
47103
48- d . ** If tests still fail after fixes:**
104+ e . ** If tests still fail after fixes:**
49105 - Try a second round of fixes if the error changed
50106 - Otherwise, report the issue with details on what was attempted
51107
521083. ** Report final results:**
53- - List which tests passed/failed
109+ - ** ALWAYS report flaky tests first** (tests that failed initially but passed on retry)
110+ - List which tests passed/failed after all retries
54111 - Document any fixes that were applied
55112 - For unfixable issues, explain why and suggest manual investigation
113+ - Show the error message and line number for any failures
56114
57115# # Important Notes
58116
0 commit comments