AI Test Repair
Automatically analyze failing tests and suggest or apply fixes. (v6.2.0)
The Problem
Tests break constantly:
- Selectors change when UI updates
- Timing issues cause flaky failures
- Page content changes break assertions
- Elements move or get renamed
Manually fixing tests is tedious and time-consuming.
The Solution
CBrowser's AI Test Repair:
- Runs your tests
- Analyzes failures
- Suggests specific fixes
- Optionally applies them automatically
- Verifies the repairs work
Quick Start
# Analyze a broken test and see suggestions
npx cbrowser repair-tests broken-test.txt
# Automatically apply repairs
npx cbrowser repair-tests tests.txt --auto-apply
# Apply repairs and verify they work
npx cbrowser repair-tests tests.txt --auto-apply --verify
# Save repaired tests to new file
npx cbrowser repair-tests tests.txt --auto-apply --output fixed-tests.txt
What It Detects
| Failure Type | Detection | Repair Strategy |
|---|---|---|
selector_not_found |
Element doesn't exist | Find alternative selectors on current page |
assertion_failed |
Verify statement false | Suggest updated assertions based on actual content |
timeout |
Step took too long | Add explicit wait statements |
element_not_interactable |
Element hidden/disabled | Add scroll/wait before interaction |
Example Output
π§ AI TEST REPAIR REPORT
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Analyzing: Login Tests
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
TEST: Login Flow
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β go to https://example.com
β Passed
β click the signin button
β Failed: Failed to click: signin button
π‘ SUGGESTIONS:
1. Update selector to "Login" (confidence: 70%)
Original: click the signin button
Fixed: click "Login"
Reason: Found button with text "Login" on page
2. Update selector to "Sign In" (confidence: 60%)
Original: click the signin button
Fixed: click "Sign In"
Reason: Found link with text "Sign In" on page
3. Add wait before click (confidence: 50%)
Original: click the signin button
Fixed: wait 2 seconds
click the signin button
Reason: Element may not be loaded yet
β type "[email protected]" in email
β Passed (skipped - previous step failed)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
TEST: Search
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β verify page contains "10 results"
β Failed: Expected "10 results", found "12 results"
π‘ SUGGESTIONS:
1. Update assertion (confidence: 90%)
Original: verify page contains "10 results"
Fixed: verify page contains "12 results"
Reason: Page now shows "12 results"
2. Use flexible assertion (confidence: 85%)
Original: verify page contains "10 results"
Fixed: verify page contains "results"
Reason: Makes test resilient to count changes
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π SUMMARY
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Tests analyzed: 2
Failed steps: 2
Suggestions generated: 5
Auto-applicable: 3
Run with --auto-apply to fix automatically
Auto-Apply Mode
When you use --auto-apply, CBrowser:
- Selects the highest-confidence suggestion for each failure
- Applies the fix to your test
- Shows what changed
npx cbrowser repair-tests tests.txt --auto-apply
π§ AUTO-APPLYING REPAIRS
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
TEST: Login Flow
Step 2: click the signin button
βββββββββββββββββββββββββββββββββ
- click the signin button
+ click "Login"
β Applied (confidence: 70%)
TEST: Search
Step 1: verify page contains "10 results"
βββββββββββββββββββββββββββββββββ
- verify page contains "10 results"
+ verify page contains "results"
β Applied (confidence: 85%)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π REPAIRS APPLIED: 2
Repaired test saved to: tests.txt.repaired
Verify Repairs
Add --verify to run the repaired tests and confirm they pass:
npx cbrowser repair-tests tests.txt --auto-apply --verify
π§ VERIFYING REPAIRS
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Running repaired tests...
TEST: Login Flow
β go to https://example.com
β click "Login" β REPAIRED
β type "[email protected]" in email
β click submit
β
PASSED
TEST: Search
β go to https://example.com/search
β type "query" in search box
β verify page contains "results" β REPAIRED
β
PASSED
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π VERIFICATION: 2/2 tests now passing
API Usage
import {
parseNLTestSuite,
repairTestSuite,
formatRepairReport,
exportRepairedTest
} from 'cbrowser';
// Parse test content
const suite = parseNLTestSuite(testContent, "My Tests");
// Run repair analysis
const result = await repairTestSuite(suite, {
autoApply: true,
verifyRepairs: true,
headless: true,
});
// Show report
console.log(formatRepairReport(result));
// Access repaired tests
for (const testResult of result.testResults) {
if (testResult.wasRepaired) {
console.log(`Repaired: ${testResult.testName}`);
console.log(exportRepairedTest(testResult));
}
}
// Get repair statistics
console.log(`Repair success rate: ${result.summary.repairSuccessRate}%`);
How the AI Works
- Failure Analysis: Parses error messages to understand what went wrong
- Page Inspection: Examines current page to find alternatives
- Pattern Matching: Compares failed selector against available elements
- Confidence Scoring: Ranks suggestions by likelihood of success
- Validation: Optionally runs repaired test to confirm fix
The AI doesn't just guessβit examines the actual page state and makes informed suggestions.
Configuration
{
"repair": {
"autoApplyThreshold": 70,
"maxSuggestionsPerStep": 3,
"preferFlexibleAssertions": true,
"addWaitsForTimeouts": true
}
}
| Option | Default | Description |
|---|---|---|
autoApplyThreshold |
70 | Minimum confidence to auto-apply |
maxSuggestionsPerStep |
3 | How many suggestions to show |
preferFlexibleAssertions |
true | Prefer resilient assertions |
addWaitsForTimeouts |
true | Add waits for timeout failures |
Best Practices
- Review before applying - Run without
--auto-applyfirst - Use
--verify- Confirm repairs actually work - Commit repaired tests - Keep your test suite up to date
- Check confidence scores - Low confidence = review manually
- Combine with flaky detection - Fix flaky tests first
Related
- Natural Language Tests - The test format this repairs
- Flaky Test Detection - Find tests that need repair
- CLI Reference - All repair-tests options
Copyright: (c) 2026 Alexa Eden.
License: MIT License
Contact: [email protected]