| name | testdriver:caching |
| description | 1.7x faster test execution with intelligent caching and optimization |
TestDriver is engineered for performance with intelligent caching that delivers up to 1.7x faster test execution by skipping redundant AI vision analysis.
await testdriver.find('submit button');
await testdriver.find('submit button');
Automatic Caching
Caching is enabled automatically with zero configuration. The cache key is computed from:
- File hash: SHA-256 hash of the test file contents
- Selector prompt: The exact text description passed to
find()
- Screenshot context: Perceptual hash of the current screen state
- Platform: Operating system and browser version
When you modify your test file, the hash changes automatically, invalidating stale cache entries and ensuring fresh AI analysis with your updated test logic.
import { test } from 'vitest';
import { chrome } from 'testdriverai/presets';
test('auto-cached test', async (context) => {
const { testdriver } = await chrome(context, {
url: 'https://example.com'
});
await testdriver.find('More information link');
await testdriver.find('More information link');
});
Managing the Cache
You can clear the cache within the TestDriver console. There, you'll also find previews of cached elements, the input prompts, as well as analytics on cache hit rates.
Manage and clear your test cache from the TestDriver console.
Debugging Cache Hits and Misses
You can track cache performance in your tests:
test('monitor cache performance', async (context) => {
const { testdriver } = await chrome(context, { url });
const element = await testdriver.find('submit button');
if (element.cacheHit) {
console.log('✅ Cache hit - instant response');
console.log('Strategy:', element.cacheStrategy);
console.log('Similarity:', `${(element.similarity * 100).toFixed(1)}%`);
console.log('Cache age:', element.cacheCreatedAt);
} else {
console.log('⏱️ Cache miss - AI analysis performed');
console.log('New cache entry created');
}
});
Configuring the Cache
You can configure cache behavior globally when initializing TestDriver:
import { TestDriver } from 'testdriverai';
const testdriver = new TestDriver({
apiKey: process.env.TD_API_KEY,
cacheKey: 'my-test-suite',
cacheDefaults: {
threshold: 0.05,
}
});
It's also possible to override cache settings per find() call:
await testdriver.find('submit button');
await testdriver.find('submit button', {
cacheThreshold: 0.01
});
Caching with Variables
Custom cache keys prevent cache pollution when using variables in prompts, dramatically improving cache hit rates.
const email = 'user@example.com';
await testdriver.find(`input for ${email}`);
const email = 'user@example.com';
await testdriver.find(`input for ${email}`, {
cacheKey: 'email-input'
});
const orderId = generateOrderId();
await testdriver.find(`order ${orderId} status`, {
cacheKey: 'order-status'
});