1.7x faster test execution with intelligent caching and optimization
Speed matters when you’re running hundreds or thousands of tests. TestDriver is engineered for performance with intelligent caching that delivers up to 1.7x faster test execution by skipping redundant AI vision analysis.
Selector caching dramatically reduces test execution time by skipping redundant AI vision analysis:
Copy
// First run: builds cacheawait testdriver.find('submit button');// Second run: exact matchawait testdriver.find('submit button');
Performance Improvement: 1.7x faster – The more you run your tests, the faster they get. Cache hits are nearly instant, turning slow AI analysis into millisecond lookups.
Caching is enabled automatically with zero configuration:
Copy
import { test } from 'vitest';import { chrome } from 'testdriverai/presets';test('auto-cached test', async (context) => { const { testdriver } = await chrome(context, { url: 'https://example.com' }); // First call: AI analyzes screen, saves to cache await testdriver.find('More information link'); // 2.1s // Second call: cache hit, instant response await testdriver.find('More information link'); // 12ms ⚡});
File-Based Cache Keys: TestDriver automatically generates cache keys from a hash of the test file calling the TestDriver methods. This means each test file has its own isolated cache namespace, preventing cache pollution between different tests while enabling fast lookups within the same test file.
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.
Automatic file-based cache keys prevent cross-test issues while enabling caching.
4. Use Custom Cache Keys with Variables
Copy
// ❌ Without cache key - creates new cache for each variable valueconst email = '[email protected]';await testdriver.find(`input for ${email}`); // Cache miss every time// ✅ With cache key - reuses cache regardless of variableconst email = '[email protected]';await testdriver.find(`input for ${email}`, { cacheKey: 'email-input'});// Also useful for dynamic IDs, names, or other changing dataconst orderId = generateOrderId();await testdriver.find(`order ${orderId} status`, { cacheKey: 'order-status' // Same cache for all orders});
Custom cache keys prevent cache pollution when using variables in prompts, dramatically improving cache hit rates.
5. Monitor Cache Hit Rates
Copy
test('track cache performance', async (context) => { const { testdriver } = await chrome(context, { url }); let cacheHits = 0; let cacheMisses = 0; const selectors = ['button 1', 'button 2', 'button 3']; for (const selector of selectors) { const element = await testdriver.find(selector); if (element.cacheHit) cacheHits++; else cacheMisses++; } console.log(`Cache hit rate: ${(cacheHits / selectors.length * 100).toFixed(0)}%`);});
Track your cache hit rates to optimize threshold settings.