Flaky tests are rarely fixed by one clever prompt. A useful fix usually needs the same disciplined QA loop every time: collect failure evidence, compare the test against product behavior, identify likely timing or data dependencies, propose a minimal change, rerun the right checks, and review the diff before merge.
That repeated loop is a good candidate for a Codex skill. OpenAI’s Codex skills documentation describes skills as reusable, task-specific bundles of instructions, resources, and optional scripts that Codex can use for a particular workflow. For QA teams, that means you can save a flaky-test review process once and reuse it across Playwright, Selenium, API, or CI failure investigations instead of rewriting the same prompt every week.
What You Are Building
In this tutorial, you will create a small Codex skill that helps review flaky automated tests. The skill will not magically prove that a test is stable. Its job is narrower and more useful: guide Codex to inspect the right evidence, avoid risky rewrites, produce a clear fix plan, and remind the tester to validate the result with targeted reruns.
The workflow is designed for QA engineers, SDETs, automation testers, and AI testing learners who already have a failing test file, a CI log, or a local failure trace.
Why Use a Skill Instead of a One-Off Prompt?
A one-off prompt is fine for a quick question. A skill is better when the task repeats and the review standard matters. Flaky-test triage usually has consistent rules:
- Do not hide failures by weakening assertions.
- Do not add broad sleeps or arbitrary delays.
- Prefer stable locators, deterministic test data, and explicit readiness checks.
- Separate product bugs from test bugs.
- Validate the fix with the smallest meaningful rerun first.
Codex best-practice guidance also supports giving the agent the goal, context, constraints, and clear done-when criteria. A skill lets you package those expectations so the next review starts from the same baseline.
Step 1: Define the Flaky-Test Review Inputs
Start by deciding what evidence the tester should provide before invoking the skill. Keep this list practical enough that a busy QA team will actually use it.
Inputs for the flaky-test review skill:
- Test file or changed diff
- Failure message and stack trace
- CI job link or local command output
- Screenshot, trace, video, or network evidence if available
- Recent product or test-data changes
- Test command used for rerun
- Expected user behavior or acceptance criteria
This input list matters because Codex cannot reliably diagnose a flaky test from a vague statement like “this test fails sometimes.” The skill should push the reviewer to supply concrete evidence before asking for a fix.
Step 2: Create the Skill Instructions
Create a focused instruction file for the skill. Keep it specific to flaky-test review instead of making it a broad test automation assistant. The narrower scope makes the output easier to review.
# Flaky Test Review Skill
You are helping a QA engineer review a flaky automated test.
Goal:
Find the most likely cause of the flake and propose the smallest safe fix.
Required review steps:
1. Summarize the failure evidence in plain language.
2. Identify whether the likely cause is timing, locator instability, test data, environment, assertion quality, or product behavior.
3. Inspect the test for risky patterns such as arbitrary delays, weak assertions, shared state, hidden order dependency, or broad retries.
4. Propose a minimal fix plan before editing.
5. Preserve meaningful assertions.
6. Recommend targeted rerun commands and any broader checks needed before merge.
7. If evidence is missing, ask for that evidence instead of guessing.
Constraints:
- Do not weaken the test just to make it pass.
- Do not replace a useful assertion with a status-only or visibility-only check.
- Do not introduce arbitrary fixed delays.
- Prefer explicit readiness signals, stable locators, isolated data, and clearer assertions.
Output format:
- Evidence summary
- Likely root cause
- Risky pattern found
- Minimal fix plan
- Validation commands
- Human review checklist
You can adapt this into the format your Codex environment expects for skills. The important part is the content: precise task scope, review steps, constraints, and a consistent output shape.
Step 3: Add Project-Specific QA Rules
Many teams already have project expectations around locators, page objects, test data, retry policies, and CI commands. Codex AGENTS.md guidance is useful here because repository instructions can encode build, test, and review expectations. Use those repository rules alongside the skill so Codex understands the local test style.
For example, a project instruction might say:
QA automation rules:
- Use role-based locators when they reflect real accessible UI behavior.
- Keep test data isolated per test when possible.
- Prefer waiting for user-visible readiness over internal implementation details.
- Run the changed spec locally before asking for review.
- Include the CI rerun command in the final note.
The skill handles the repeated flaky-test workflow. The repository guidance handles project-specific norms.
Step 4: Invoke the Skill on a Real Failure
When a test fails in CI, start with evidence instead of a fix request. A good prompt looks like this:
Use the flaky-test review skill.
Context:
- This Playwright checkout test fails intermittently in CI.
- It passed locally once but failed twice in the browser project used by CI.
- The failure message says the confirmation text was not visible before timeout.
Files and evidence:
- Review the changed test file.
- Review this failure log.
- Review the attached trace summary if available.
Task:
Summarize the evidence, identify the likely root cause, propose a minimal fix plan, and list the validation commands before editing.
Notice the order: review first, fix second. This keeps Codex from jumping straight to a broad rewrite.
Step 5: Review the Proposed Fix Like a QA Engineer
After Codex proposes a change, inspect it before accepting. For flaky-test work, the highest-risk AI-generated changes are usually easy to spot:
- The assertion became weaker than the original user requirement.
- The test now passes by waiting longer instead of waiting better.
- The locator became less user-focused or more tied to layout structure.
- The fix hides a real product race condition.
- The rerun plan only checks the happy path once.
Codex CLI review support can help here because `/review` is designed to inspect selected diffs and return prioritized findings without changing the working tree. That makes it useful after the first proposed patch: ask Codex to review the diff for test reliability risk before you merge it.
Step 6: Validate With Targeted Reruns
A flaky-test fix is not complete when the code compiles. The skill should always end with validation commands. Keep them specific:
Suggested validation sequence:
1. Run the changed test file locally.
2. Run the same test in the browser or environment that failed in CI.
3. Repeat the focused test enough times to catch obvious instability.
4. Run the nearby suite if the fix touches shared helpers.
5. Recheck the final diff before merge.
For a Playwright suite, that might mean running one changed spec first, then a related project or shard. For Selenium, it might mean the affected test class and the shared page object tests. For API tests, it might mean the endpoint collection plus contract checks.
Screenshot Plan for the Tutorial
If you are documenting this workflow for your team, capture screenshots at these points:
- The CI failure log with the flaky test name and error message visible.
- The Codex prompt invoking the flaky-test review skill.
- The structured Codex output showing evidence summary, likely root cause, and minimal fix plan.
- The code diff after the proposed fix.
- The focused rerun command and passing result.
- The final review checklist before merge.
Reusable QA Checklist
Before closing the flaky-test investigation, use this checklist:
- Did the fix preserve the original user-facing assertion?
- Did it remove or reduce the actual source of instability?
- Did it avoid arbitrary fixed delays?
- Did it keep test data isolated?
- Did it document the validation commands?
- Did a human reviewer inspect the final diff?
Common Mistakes to Avoid
The biggest mistake is treating AI output as proof. Codex can help organize evidence, suggest likely root causes, and draft a minimal change, but the QA engineer still owns the final judgment. A flaky test may point to a test bug, a product timing issue, missing test data isolation, or an environment problem. The skill should make that decision easier to review, not automatic.
The second mistake is creating a skill that is too broad. If your skill tries to cover flaky UI tests, API contract review, accessibility checks, performance triage, and release notes at the same time, it becomes a generic prompt. Keep this one focused on flaky-test review and create separate skills for other repeated QA workflows.
Final Takeaway
A Codex skill is most useful when it captures a repeatable QA habit. For flaky tests, that habit is evidence first, root cause second, minimal fix third, validation last. Once that process is reusable, Codex becomes a more consistent test-review partner and your QA team spends less time rewriting the same triage prompt.
Sources reviewed: OpenAI Codex skills, Codex best practices, Codex CLI features, AGENTS.md guidance, and Codex app review documentation.

