Analyze Flaky Tests logo

Analyze Flaky Tests

Community
anhtester
analyze-flaky-tests

Phân tích automation tests không ổn định (flaky), xác định root cause và tự động khắc phục. Hỗ trợ 2 mode — ANALYZE (chỉ báo cáo) và FIX (báo cáo + tự sửa code).

Overview

Publisheranhtester
Repositorycodex-testing-kit
Skill nameanalyze-flaky-tests
Stars
34
Forks
14
Bundled files
1
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by anhtester on GitHub. Read the source before you install it.

Installation

Install the Analyze Flaky Tests AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/anhtester/codex-testing-kit/tree/main/.agents/skills/analyze-flaky-tests
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/anhtester/codex-testing-kit.git /tmp/codex-testing-kit
mkdir -p .claude/skills
cp -r /tmp/codex-testing-kit/.agents/skills/analyze-flaky-tests .claude/skills/analyze-flaky-tests
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Analyze Flaky Tests in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Analyze Flaky Tests on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Analyze Flaky Tests is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Workflow: Phân Tích & Khắc Phục Flaky Tests

BẮT BUỘC (MANDATORY SKILL): Bạn PHẢI nạp và đọc kỹ nội dung của skill $flaky-test-analyzer (tại .agents/skills/flaky-test-analyzer/SKILL.md) trước khi bắt đầu. Ngoài ra, tham khảo thêm skill $smart-locator-agent và $locator-healer-agent khi cần sửa/thay locator.

Workflow này giúp agent tự động phân tích các automation test không ổn định (lúc pass lúc fail), xác định root cause chính xác, và (tùy mode) tự động sửa code để stabilize test.

⚠️ Nguyên tắc thực thi

  • Tất cả output bằng Tiếng Việt
  • KHÔNG đoán nguyên nhân — phải phân tích log, code, và DOM thực tế
  • Phải chờ user xác nhận danh sách fix tại Bước 3 trước khi sửa code (Mode FIX)
  • Nếu user chưa cung cấp test file/error log → hỏi trước khi bắt đầu
  • ⚠️ Sau khi user xác nhận fix → agent tự sửa + verify, KHÔNG hỏi lại trong quá trình fix

2 Chế độ (Mode)

ModeKhi nào sử dụngOutput
ANALYZE (mặc định)User cần hiểu nguyên nhân flaky, chưa muốn sửa codeBáo cáo phân tích + Đề xuất fix
FIXUser muốn agent tự sửa code luônNhư ANALYZE + Code đã sửa + Kết quả verify

Nếu user nói "sửa luôn", "fix giùm", "khắc phục test này", hoặc yêu cầu agent sửa code → tự động chuyển sang Mode FIX.

Input cần thu thập

Agent cần ít nhất 1 trong các input sau từ user:

InputCách lấyĐộ ưu tiên
Test file pathUser cung cấp hoặc agent tìm trong project⭐ Bắt buộc
Error log / stack traceUser paste hoặc agent chạy test để thu thập⭐ Bắt buộc
CI/CD logUser cung cấp URL hoặc file logTùy chọn
Test report (HTML/JSON)Playwright report, Allure, TestNG reportTùy chọn
Lịch sử failSố lần fail / tổng số lần chạyTùy chọn

Các bước thực hiện

Bước 1: Thu thập thông tin & Tái hiện lỗi (Detect & Reproduce)

  1. Đọc test file bằng view_file:

    • Xác định framework (Playwright / Selenium / Appium / Pytest / TestNG)
    • Ghi nhận cấu trúc: Page Objects, fixtures, helper functions
    • Đánh dấu các vùng code nghi ngờ (waits, locators, assertions, setup/teardown)
  2. Chạy test để tái hiện lỗi (nếu chưa có error log):

    • Chạy test 3 lần liên tiếp bằng run_command:
      bash
      # Playwright
      npx playwright test <test_file> --retries=0 --reporter=list
      
      # Pytest
      python -m pytest <test_file> -v --count=3
      
      # Maven/TestNG
      mvn test -Dtest=<TestClass> -Dsurefire.rerunFailingTestsCount=0
    • Ghi nhận pattern: Fail lần nào? Fail ở step nào? Error message giống hay khác nhau?
  3. Thu thập evidence:

    • Error log / stack trace từ mỗi lần chạy
    • Screenshots (nếu test có capture on failure)
    • Console log / Network log (nếu liên quan đến API calls)

Bước 2: Phân tích Root Cause (Inspect & Classify)

  1. Đọc error log và phân loại theo bảng root cause:
CategoryDấu hiệu nhận biếtVí dụ Error
🎯 Locator không ổn địnhElementNotFound, No matching element, selector chứa dynamic class/indexLocator('.css-1a2b3c') fail vì class thay đổi mỗi build
⏱️ Timing / Race conditionTimeout, Element not visible, test pass khi chạy chậm (debug mode)expect(element).toBeVisible() timeout vì animation chưa xong
📊 Test data conflictDuplicate key, Already exists, fail khi chạy parallel2 test cùng tạo user test@email.com
🔄 State dependencyPass khi chạy độc lập, fail khi chạy cùng suiteTest B phụ thuộc data mà Test A tạo ra
🌐 Environment / NetworkECONNREFUSED, 503, CORS error, fail trên CI nhưng pass localAPI server chậm, CDN timeout
🖼️ UI Animation / TransitionElement is not clickable, intercept, fail ngẫu nhiên khi clickModal animation chưa hoàn thành, overlay che button
📱 Viewport / ResponsiveElement bị ẩn, scroll không tới, fail ở resolution khácButton nằm ngoài viewport trên CI (headless 800x600)
🧹 Cleanup / TeardownFail ở lần chạy thứ 2+, pass lần đầuTest không cleanup data → lần sau bị conflict
  1. Inspect code chi tiết, kiểm tra từng anti-pattern:

    Locator check:

    • Có dùng dynamic class (css-xxx, sc-xxx, MuiXxx-root)? → ❌
    • Có dùng positional xpath (//div[3]/button[2])? → ❌
    • Locator có unique không? (kiểm tra trên DOM thực tế nếu cần)

    Wait strategy check:

    • Có waitForTimeout() / Thread.sleep() / time.sleep()? → ❌
    • Có waitForSelector() khi expect() đã đủ? → ⚠️
    • Assertion có timeout phù hợp không?

    Test data check:

    • Data có hardcoded không? (test@email.com, user123)
    • Data có unique per run không? (timestamp / random)
    • Có cleanup data sau test không?

    Test independence check:

    • Test có phụ thuộc thứ tự chạy không?
    • Test có share state qua global variable không?
    • Setup/Teardown có đầy đủ không?
  2. Nếu cần inspect DOM thực tế (locator issue):

    • Mở browser bằng MCP: browser_navigate → browser_resize(1920, 1080) → browser_snapshot
    • So sánh locator trong code vs DOM thực tế
    • Xác định locator thay thế ổn định hơn (dùng skill $smart-locator-agent)

Bước 3: Lập báo cáo & Đề xuất fix (Report — CHECKPOINT)

  1. Tạo artifact flaky_analysis.md với cấu trúc:

    markdown
    # Báo Cáo Phân Tích Flaky Test
    
    ## Tổng quan
    - **Test file:** <path>
    - **Framework:** Playwright / Selenium / ...
    - **Tần suất fail:** X/Y lần chạy
    - **Mức độ nghiêm trọng:** 🔴 Critical / 🟡 Medium / 🟢 Low
    
    ## Root Cause Analysis
    
    | # | Vị trí (Line) | Category | Mô tả vấn đề | Mức độ |
    |---|---|---|---|---|
    | 1 | test.ts:45 | ⏱️ Timing | waitForTimeout(3000) thay vì smart wait | 🔴 |
    | 2 | page.ts:12 | 🎯 Locator | .css-1abc dynamic class | 🟡 |
    
    ## Đề xuất Fix
    
    | # | Vấn đề | Code hiện tại | Code đề xuất | Lý do |
    |---|---|---|---|---|
    | 1 | Hard sleep | `waitForTimeout(3000)` | `expect(el).toBeVisible()` | Smart wait tự retry |
    | 2 | Dynamic class | `.css-1abc` | `getByRole('button', {name: 'Submit'})` | Semantic, không phụ thuộc CSS |
  2. ⏸️ DỪNG LẠI — Trình bày cho user review:

    • Danh sách root causes đã xác định
    • Bảng đề xuất fix (code cũ → code mới)
    • Hỏi: "Bạn đồng ý với phân tích này không? Tôi tiến hành sửa code luôn hay chỉ cần báo cáo?"
  3. Nếu user chọn Mode ANALYZE → KẾT THÚC tại đây

  4. Nếu user đồng ý fix → chuyển sang Bước 4

Bước 4: Tự động sửa code (Auto-Fix — Mode FIX)

Chỉ thực hiện khi ở Mode FIX và user đã xác nhận

  1. Sửa code theo thứ tự ưu tiên (fix nghiêm trọng nhất trước):

    Fix Locator:

    • Dùng skill $locator-healer-agent để thay thế locator hỏng
    • Tuân thủ locator priority trong .agents/rules/locator_strategy.md
    • Verify locator mới trên DOM thực tế trước khi commit vào code

    Fix Timing:

    ❌ page.waitForTimeout(3000)
    ✅ await expect(page.getByRole('button')).toBeVisible()
    
    ❌ Thread.sleep(5000)
    ✅ wait.until(ExpectedConditions.visibilityOfElementLocated(...))

    Fix Test Data:

    ❌ const email = "test@email.com"
    ✅ const email = `auto_${Date.now()}@test.com`

    Fix Test Independence:

    • Thêm setup/teardown để tạo và cleanup data riêng
    • Loại bỏ dependency giữa các test cases
    • Đảm bảo mỗi test tự tạo precondition riêng
  2. Sử dụng replace_file_content hoặc multi_replace_file_content để áp dụng thay đổi

  3. Ghi chú mỗi thay đổi vào artifact flaky_analysis.md

Bước 5: Verify & Đảm bảo ổn định (Verify Stability)

Chỉ thực hiện khi ở Mode FIX

  1. Chạy test 3 lần liên tiếp sau khi fix:

    bash
    # Playwright
    npx playwright test <test_file> --retries=0 --repeat-each=3
    
    # Pytest
    python -m pytest <test_file> -v --count=3
    
    # Maven
    mvn test -Dtest=<TestClass> (chạy 3 lần thủ công)
  2. Đánh giá kết quả:

    Kết quảHành động
    ✅ 3/3 PASSTest đã ổn định → cập nhật artifact, báo cáo thành công
    ⚠️ 2/3 PASSVẫn còn flaky → quay lại Bước 2 phân tích lần fail, fix tiếp (tối đa 3 vòng)
    ❌ 0-1/3 PASSFix sai hướng → rollback, phân tích lại root cause
  3. Stability Checklist (phải đạt toàn bộ trước khi kết thúc):

    • Locator unique và ổn định qua nhiều lần reload
    • Không có hard sleep / fixed delay
    • Test data unique + traceable mỗi lần chạy
    • Test độc lập — không phụ thuộc thứ tự chạy
    • Test pass 3+ lần liên tiếp
    • Không còn debug log / commented code
  4. Cập nhật artifact flaky_analysis.md:

    • Thêm section "Kết quả sau fix" với bảng kết quả chạy
    • Đánh dấu trạng thái: ✅ STABILIZED / ⚠️ PARTIALLY FIXED / ❌ STILL FLAKY

Xử lý các tình huống đặc biệt

Tình huốngCách xử lý
Test chỉ fail trên CISo sánh env CI vs local (viewport, timezone, headless, resources). Kiểm tra viewport 1920x1080 có được set trên CI không
Test fail khi chạy parallelKiểm tra test data isolation, shared state, database locks. Đề xuất unique data per worker
Test fail sau deploy mớiKiểm tra DOM changes, API response changes. Dùng $locator-healer-agent để update locators
Test fail ngẫu nhiên không patternThu thập thêm data (chạy 10+ lần), kiểm tra memory leak, resource exhaustion
Multiple tests cùng flakyTìm common factor (shared fixture, shared page object, shared config)
Test fail do external APIĐề xuất mock/stub external dependencies, retry logic cho API calls

Output

Mode ANALYZE

  • Artifact flaky_analysis.md:
    • Tổng quan test (file, framework, tần suất fail)
    • Root Cause Analysis (bảng phân loại)
    • Đề xuất fix chi tiết (code cũ → code mới)
    • Stability checklist

Mode FIX

  • Tất cả output của Mode ANALYZE, cộng thêm:
    • Code đã được sửa (các file đã thay đổi)
    • Kết quả verify (3 lần chạy PASS/FAIL)
    • Trạng thái cuối: STABILIZED / PARTIALLY FIXED / STILL FLAKY

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Analyze Flaky Tests AI skill do?

Phân tích automation tests không ổn định (flaky), xác định root cause và tự động khắc phục. Hỗ trợ 2 mode — ANALYZE (chỉ báo cáo) và FIX (báo cáo + tự sửa code).

Why use Analyze Flaky Tests on TypingMind?

Because you install it once and use it with any model. Analyze Flaky Tests is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Analyze Flaky Tests in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/anhtester/codex-testing-kit/tree/main/.agents/skills/analyze-flaky-tests. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Analyze Flaky Tests?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Analyze Flaky Tests?

As many as you like. As long as a model supports skills, you can use Analyze Flaky Tests with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Analyze Flaky Tests AI skill free?

Yes. It is published on GitHub by anhtester under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇