-
-
Notifications
You must be signed in to change notification settings - Fork 751
Add AI Trace plugin for AI-assisted debugging #5432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b80e931
add aiTrace plugin for AI-assisted test debugging
DenysKuchma bc43021
add path and little fix
DenysKuchma b362e47
add pr fix
DenysKuchma ca575c9
fix test
DenysKuchma adbbcd8
fix bug and add test support to testomatio
DenysKuchma 7f9ea43
Add mcp server (#5452)
DenysKuchma d3ed088
Merge branch '4.x' into feature/5425-ai-trace-plugin
DavertMik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,279 @@ | ||
| --- | ||
| permalink: /aitrace | ||
| title: AI Trace Plugin | ||
| --- | ||
|
|
||
| # AI Trace Plugin | ||
|
|
||
| AI Trace Plugin generates AI-friendly trace files for debugging with AI agents like Claude Code. | ||
|
|
||
| When a test fails, you need to understand what went wrong: what the page looked like, what elements were present, what errors occurred, and what led to the failure. This plugin automatically captures all that information and organizes it in a format optimized for AI analysis. | ||
|
|
||
| ## Quick Start | ||
|
|
||
| Enable the plugin in your `codecept.conf.js`: | ||
|
|
||
| ```javascript | ||
| export const config = { | ||
| tests: './*_test.js', | ||
| output: './output', | ||
| helpers: { | ||
| Playwright: { | ||
| url: 'https://example.com', | ||
| // Optional: Enable HAR/trace for HTTP capture | ||
| recordHar: { | ||
| mode: 'minimal', | ||
| content: 'embed', | ||
| }, | ||
| trace: 'on', | ||
| keepTraceForPassedTests: true, | ||
| }, | ||
| }, | ||
| plugins: { | ||
| aiTrace: { | ||
| enabled: true, | ||
| }, | ||
| }, | ||
| } | ||
| ``` | ||
|
|
||
| Run tests: | ||
|
|
||
| ```bash | ||
| npx codeceptjs run | ||
| ``` | ||
|
|
||
| After test execution, trace files are created in `output/trace_*/trace.md`. | ||
|
|
||
| ## Artifacts Created | ||
|
|
||
| For each test, a `trace_<sha256>` directory is created with the following files: | ||
|
|
||
| **trace.md** - AI-friendly markdown file with test execution history | ||
|
|
||
| **0000_screenshot.png** - Screenshot for each step | ||
|
|
||
| **0000_page.html** - Full HTML of the page at each step | ||
|
|
||
| **0000_aria.txt** - ARIA accessibility snapshot (AI-readable structure without HTML noise) | ||
|
|
||
| **0000_console.json** - Browser console logs | ||
|
|
||
| When HAR or trace recording is enabled in your helper config, links to those files are also included. | ||
|
|
||
| ## Trace File Format | ||
|
|
||
| The `trace.md` file contains a structured execution log with links to all artifacts: | ||
|
|
||
| ```markdown | ||
| file: /path/to/test.js | ||
| name: My test scenario | ||
| time: 3.45s | ||
| --- | ||
|
|
||
| I am on page "https://example.com" | ||
| > navigated to https://example.com/ | ||
| > [HTML](./0000_page.html) | ||
| > [ARIA Snapshot](./0000_aria.txt) | ||
| > [Screenshot](./0000_screenshot.png) | ||
| > [Browser Logs](0000_console.json) (7 entries) | ||
| > HTTP: see [HAR file](../har/...) for network requests | ||
|
|
||
| I see "Welcome" | ||
| > navigated to https://example.com/ | ||
| > [HTML](./0001_page.html) | ||
| > [ARIA Snapshot](./0001_aria.txt) | ||
| > [Screenshot](./0001_screenshot.png) | ||
| > [Browser Logs](0001_console.json) (0 entries) | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### Basic Configuration | ||
|
|
||
| ```javascript | ||
| plugins: { | ||
| aiTrace: { | ||
| enabled: true, | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Advanced Configuration | ||
|
|
||
| ```javascript | ||
| plugins: { | ||
| aiTrace: { | ||
| enabled: true, | ||
|
|
||
| // Artifact capture options | ||
| captureHTML: true, // Save HTML for each step | ||
| captureARIA: true, // Save ARIA snapshots | ||
| captureBrowserLogs: true, // Save console logs | ||
| captureHTTP: true, // Links to HAR/trace files | ||
| captureDebugOutput: true, // CodeceptJS debug messages | ||
|
|
||
| // Screenshot options | ||
| fullPageScreenshots: false, // Full page or viewport only | ||
|
|
||
| // Output options | ||
| output: './output', // Where to save traces | ||
| deleteSuccessful: false, // Delete traces for passed tests | ||
|
|
||
| // Step filtering | ||
| ignoreSteps: [ | ||
| /^grab/, // Ignore all grab* steps | ||
| /^wait/, // Ignore all wait* steps | ||
| ], | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Configuration Options | ||
|
|
||
| | Option | Type | Default | Description | | ||
| |--------|------|---------|-------------| | ||
| | `enabled` | boolean | `false` | Enable/disable the plugin | | ||
| | `captureHTML` | boolean | `true` | Capture HTML for each step | | ||
| | `captureARIA` | boolean | `true` | Capture ARIA snapshots | | ||
| | `captureBrowserLogs` | boolean | `true` | Capture browser console logs | | ||
| | `captureHTTP` | boolean | `true` | Capture HTTP requests (requires HAR/trace) | | ||
| | `captureDebugOutput` | boolean | `true` | Capture CodeceptJS debug output | | ||
| | `fullPageScreenshots` | boolean | `false` | Use full page screenshots | | ||
| | `output` | string | `'./output'` | Directory for trace files | | ||
| | `deleteSuccessful` | boolean | `false` | Delete traces for passed tests | | ||
| | `ignoreSteps` | array | `[]` | Steps to ignore (regex patterns) | | ||
|
|
||
| ## Best Practices | ||
|
|
||
| ### Optimize for Failing Tests | ||
|
|
||
| Save disk space by only keeping traces for failed tests: | ||
|
|
||
| ```javascript | ||
| plugins: { | ||
| aiTrace: { | ||
| enabled: true, | ||
| deleteSuccessful: true, // Only keep failing tests | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Ignore Noise | ||
|
|
||
| Don't capture logs for `grab` and `wait` steps: | ||
|
|
||
| ```javascript | ||
| plugins: { | ||
| aiTrace: { | ||
| enabled: true, | ||
| ignoreSteps: [/^grab/, /^wait/], | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Selective Artifact Capture | ||
|
|
||
| Capture only what you need to reduce file sizes: | ||
|
|
||
| ```javascript | ||
| plugins: { | ||
| aiTrace: { | ||
| enabled: true, | ||
| captureHTML: false, // Skip HTML (saves ~500KB per step) | ||
| captureARIA: true, // Keep ARIA (only ~16KB) | ||
| captureBrowserLogs: false, // Skip console logs | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Enable HTTP Capture | ||
|
|
||
| For network debugging, enable HAR/trace in your helper: | ||
|
|
||
| ```javascript | ||
| helpers: { | ||
| Playwright: { | ||
| recordHar: { | ||
| mode: 'minimal', | ||
| content: 'embed', | ||
| }, | ||
| trace: 'on', | ||
| keepTraceForPassedTests: true, | ||
| }, | ||
| plugins: { | ||
| aiTrace: { | ||
| enabled: true, | ||
| captureHTTP: true, // Links to HAR/trace files | ||
| }, | ||
| }, | ||
| } | ||
| ``` | ||
|
|
||
| ## Using with AI Agents | ||
|
|
||
| The trace format is optimized for AI agents like Claude Code. When debugging a failing test: | ||
|
|
||
| 1. Open the generated `trace.md` file | ||
| 2. Copy its contents along with relevant artifact files (ARIA snapshots, console logs, etc.) | ||
| 3. Provide to the AI agent with context about the failure | ||
|
|
||
| Example prompt: | ||
| ``` | ||
| I have a failing test. Here's the AI trace: | ||
|
|
||
| [paste trace.md contents] | ||
|
|
||
| [paste relevant ARIA snapshots] | ||
|
|
||
| [paste console logs] | ||
|
|
||
| Analyze this and explain why the test failed and how to fix it. | ||
| ``` | ||
|
|
||
| The AI agent can analyze all artifacts together - screenshots, HTML structure, console errors, and network requests - to provide comprehensive debugging insights. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### No trace files created | ||
|
|
||
| **Possible causes:** | ||
| 1. Plugin not enabled | ||
| 2. No steps executed | ||
| 3. Tests skipped | ||
|
|
||
| **Solution:** | ||
| ```bash | ||
| # Check if plugin is enabled | ||
| grep -A 5 "aiTrace" codecept.conf.js | ||
|
|
||
| # Run with verbose output | ||
| npx codeceptjs run --verbose | ||
| ``` | ||
|
|
||
| ### ARIA snapshots missing | ||
|
|
||
| **Possible cause:** Helper doesn't support `grabAriaSnapshot` | ||
|
|
||
| **Solution:** Use Playwright or update to latest CodeceptJS | ||
|
|
||
| ### HAR files missing | ||
|
|
||
| **Possible cause:** HAR/trace not enabled in helper config | ||
|
|
||
| **Solution:** | ||
| ```javascript | ||
| helpers: { | ||
| Playwright: { | ||
| recordHar: { mode: 'minimal' }, | ||
| trace: 'on', | ||
| }, | ||
| } | ||
| ``` | ||
|
|
||
| ## Related | ||
|
|
||
| - [AI Features](/ai) - AI-powered testing features | ||
| - [Plugins](/plugins) - All available plugins | ||
| - [Configuration](/configuration) - General configuration | ||
| - [Playwright Helper](/playwright) - Playwright-specific configuration | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.