Speed up tests with screenshot-based caching
npx skills add https://github.com/testdriverai/testdriverai --skill testdriver:cache
<!-- Generated from cache.mdx. DO NOT EDIT. -->
The cache system speeds up repeated test runs by comparing screenshots to cached results. When the screen hasn't changed significantly, cached element positions are reused instead of making an AI call.
Cache works at two levels:
find(), the SDK sends the current screenshot and cache metadata to the APIcacheKeyscreen threshold AND the element template match exceeds the element threshold, the cached position is returnedflowchart LR
A[Screenshot + cacheKey] --> B{Screen Diff\n< threshold?}
B -- Yes --> C{Template\nMatch OK?}
C -- Yes --> D[Return cached position]
B -- No --> E[AI Call - fresh]
C -- No --> F[AI Call - fresh]
const testdriver = new TestDriver({
cache: {
enabled: true,
thresholds: {
find: {
screen: 0.05, // 5% pixel diff allowed (default)
element: 0.8, // 80% OpenCV correlation required (default)
},
assert: 0.05, // 5% pixel diff for assertions (default)
},
},
cacheKey: 'my-custom-key', // overrides auto-generated key
});
<ParamField path="cache" type="CacheConfig | false">
Cache configuration object, or false to disable entirely.
<Expandable title="properties">
<ParamField path="enabled" type="boolean" default={true}>
Enable or disable the cache system. Requires a valid cacheKey to actually activate.
</ParamField>
<ParamField path="thresholds" type="CacheThresholds">
Threshold configuration for different command types.
<Expandable title="properties">
<ParamField path="find" type="FindCacheThresholds">
Thresholds for find() and findAll().
<Expandable title="properties">
<ParamField path="screen" type="number" default={0.05}>
Maximum pixel diff percentage allowed between the current screenshot and the cached screenshot. Lower values require a closer match. Range: 0 to 1.
</ParamField>
<ParamField path="element" type="number" default={0.8}>
Minimum OpenCV template matching correlation required for the cached element crop. Higher values require a closer match. Range: 0 to 1. Only used for find(), not findAll().
</ParamField>
</Expandable>
</ParamField>
<ParamField path="assert" type="number" default={0.05}>
Maximum pixel diff allowed for assertion cache hits.
</ParamField>
</Expandable>
</ParamField>
</Expandable>
</ParamField>
<ParamField path="cacheKey" type="string">
Unique key for cache lookups. If not provided, an auto-generated key is created from a SHA-256 hash of the calling test file (first 16 hex characters). The cache key changes automatically when your test file changes, providing automatic cache invalidation.
</ParamField>
// Via constructor
const testdriver = new TestDriver({ cache: false });
// Via environment variable
// TD_NO_CACHE=true npx vitest run
When cache is disabled, all thresholds are set to -1 internally, causing the API to skip cache lookups.
Override cache thresholds for individual commands:
// Stricter screen matching for this specific find
const el = await testdriver.find('submit button', {
cache: {
thresholds: { screen: 0.01, element: 0.95 },
},
});
// Custom cache key for a specific assertion
await testdriver.assert('dashboard loaded', {
cache: { threshold: 0.01 },
cacheKey: 'dashboard-check',
});
Thresholds are resolved in priority order (highest wins):
| Priority | Source | Example |
|----------|--------|---------|
| 1 (highest) | Per-command option | find(desc, { cache: { thresholds: { screen: 0.1 } } }) |
| 2 | Legacy number argument | find(desc, 0.1) |
| 3 | Global constructor config | new TestDriver({ cache: { thresholds: { find: { screen: 0.1 } } } }) |
| 4 (lowest) | Hard-coded defaults | screen: 0.05, element: 0.8, assert: 0.05 |
When you don't specify a cacheKey, the SDK automatically generates one:
This means:
// Auto-generated cache key from test file hash
const testdriver = new TestDriver();
// cacheKey = "a3f2b1c4d5e6f7a8" (auto)
// Manual override
const testdriver = new TestDriver({ cacheKey: 'login-test-v2' });
Element cache validation uses OpenCV's normalized cross-correlation coefficient (TM_CCOEFF_NORMED) to verify that the cached element is still visible at the expected position.
Algorithm:
cv.matchTemplate() with TM_CCOEFF_NORMED{ x, y, width, height, centerX, centerY }Scale factors tried: [1, 0.5, 2, 0.75, 1.25, 1.5]
Thresholds tried: [0.9, 0.8, 0.7] (picks highest matching threshold)
This accounts for minor scaling differences between screenshots taken at different times or resolutions.
Cache entries are partitioned by:
cacheKey — identifies the test fileos — operating system (linux, windows, darwin)resolution — screen resolutionThis means cache from a Linux run won't be used for a Windows run, even with the same cache key.
API responses include cache metadata:
| Field | Description |
|---|---|
| cacheHit | true if cache was used |
| similarity | Pixel diff percentage between screenshots |
| cacheSimilarity | OpenCV template match score |
Use getDebugInfo() on an element to inspect cache results:
const el = await testdriver.find('submit button');
const debug = el.getDebugInfo();
console.log(debug);
// { cacheHit: true, similarity: 0.02, cacheSimilarity: 0.92, ... }
interface CacheConfig {
enabled?: boolean; // Default: true
thresholds?: CacheThresholds;
}
interface CacheThresholds {
find?: FindCacheThresholds;
assert?: number; // Default: 0.05
}
interface FindCacheThresholds {
screen?: number; // Default: 0.05
element?: number; // Default: 0.8
}
interface CacheDebugInfo {
cacheHit: boolean;
similarity: number;
cacheSimilarity: number;
}
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup
Use when implementing any feature or bugfix, before writing implementation code
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always
Expert guidance for systematic backtesting of trading strategies. Use when developing, testing, stress-testing, or validating quantitative trading strategies. Covers "beating ideas to death" methodology, parameter robustness testing, slippage modeling, bias prevention, and interpreting backtest results. Applicable when user asks about backtesting, strategy validation, robustness testing, avoiding overfitting, or systematic trading development.
Cloud laboratory platform for automated protein testing and validation. Use when designing proteins and needing experimental validation including binding assays, expression testing, thermostability measurements, enzyme activity assays, or protein sequence optimization. Also use for submitting experiments via API, tracking experiment status, downloading results, optimizing protein sequences for better expression using computational tools (NetSolP, SoluProt, SolubleMPNN, ESM), or managing protein design workflows with wet-lab validation.
This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.
Take testdriverai/testdriver:cache from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.
The instructions reference npx.
Without those the skill loads but fails at the first command.