$npx -y skills add anhtester/codex-testing-kit --skill flaky-test-analyzerSkill phân tích và khắc phục các automation test không ổn định (flaky tests), xác định root cause và đề xuất fix.
| 1 | # Flaky Test Analyzer |
| 2 | |
| 3 | Purpose: Identify and resolve unstable automation tests. |
| 4 | |
| 5 | --- |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | Use this skill when: |
| 10 | |
| 11 | - A test passes and fails intermittently |
| 12 | - Test results are inconsistent across runs |
| 13 | - CI/CD pipeline has unreliable test results |
| 14 | |
| 15 | --- |
| 16 | |
| 17 | ## Responsibilities |
| 18 | |
| 19 | Detect flaky tests caused by: |
| 20 | |
| 21 | - Unstable locators (dynamic classes, positional xpath) |
| 22 | - Timing issues (race conditions, slow page loads) |
| 23 | - Incorrect waits (hard sleep instead of smart waits) |
| 24 | - Environment dependency (data not cleaned up, external service down) |
| 25 | - Test data conflicts (shared data between parallel tests) |
| 26 | |
| 27 | --- |
| 28 | |
| 29 | ## Analysis Workflow |
| 30 | |
| 31 | 1. **Detect** — Identify the failing test and reproduce the failure |
| 32 | 2. **Inspect** — Read error logs, stack traces, and screenshots |
| 33 | 3. **Classify** — Categorize the root cause (locator / timing / data / environment) |
| 34 | 4. **Fix** — Apply the appropriate fix strategy |
| 35 | 5. **Verify** — Re-run test multiple times to confirm stability |
| 36 | |
| 37 | --- |
| 38 | |
| 39 | ## Common Flaky Causes & Fixes |
| 40 | |
| 41 | ### Unstable Locator |
| 42 | |
| 43 | **Problem:** |
| 44 | ``` |
| 45 | //div[3]/button |
| 46 | .css-1n2xyz-btn |
| 47 | ``` |
| 48 | |
| 49 | **Fix:** Replace with stable locator following priority in `.agents/rules/locator_strategy.md`: |
| 50 | - `id`, `data-testid`, `name`, `css selector` (stable), `xpath` (relative) |
| 51 | |
| 52 | --- |
| 53 | |
| 54 | ### Timing Issues |
| 55 | |
| 56 | **Problem:** |
| 57 | ```java |
| 58 | Thread.sleep(3000); // Hard sleep — BAD |
| 59 | page.waitForTimeout(2000); // Fixed delay — BAD |
| 60 | ``` |
| 61 | |
| 62 | **Fix:** Use smart waits as defined in `.agents/rules/selenium_rules.md` and `.agents/rules/playwright_rules.md`: |
| 63 | ```java |
| 64 | // Selenium |
| 65 | WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); |
| 66 | wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("result"))); |
| 67 | |
| 68 | // Playwright |
| 69 | await expect(page.getByRole('button', { name: 'Submit' })).toBeVisible(); |
| 70 | ``` |
| 71 | |
| 72 | --- |
| 73 | |
| 74 | ### Test Data Conflicts |
| 75 | |
| 76 | **Problem:** Tests share mutable data → parallel runs conflict. |
| 77 | |
| 78 | **Fix:** Use unique, traceable random data: |
| 79 | ``` |
| 80 | <testName>_<timestamp>@test.com |
| 81 | ``` |
| 82 | |
| 83 | --- |
| 84 | |
| 85 | ## Stability Checklist |
| 86 | |
| 87 | After fixing a flaky test, verify: |
| 88 | |
| 89 | - [ ] Locator is unique and stable across reloads |
| 90 | - [ ] No hard sleep or fixed delays |
| 91 | - [ ] Test data is unique and deterministic |
| 92 | - [ ] Test is independent (no dependency on other tests) |
| 93 | - [ ] Test passes 5+ consecutive runs |
| 94 | |
| 95 | --- |
| 96 | |
| 97 | ## Rules References |
| 98 | |
| 99 | The agent MUST follow these rules when analyzing flaky tests: |
| 100 | |
| 101 | - `.agents/rules/locator_strategy.md` — Locator stability rules |
| 102 | - `.agents/rules/automation_rules.md` — General automation best practices |
| 103 | - `.agents/rules/selenium_rules.md` — Selenium wait strategy |
| 104 | - `.agents/rules/playwright_rules.md` — Playwright auto-waiting |