self-healing-playwright
Version:
Self-healing locators for Playwright tests using AI-powered healing strategies
41 lines (40 loc) • 1.41 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocatorCache = void 0;
const node_cache_1 = __importDefault(require("node-cache"));
class LocatorCache {
constructor() {
this.cache = new node_cache_1.default({
stdTTL: 3600, // 1 hour default TTL
checkperiod: 120, // Check for expired keys every 2 minutes
useClones: false
});
}
async getCachedLocator(originalLocator, context) {
const cacheKey = this.generateCacheKey(originalLocator, context);
return this.cache.get(cacheKey) || null;
}
async setCachedLocator(originalLocator, context, healedLocator) {
const cacheKey = this.generateCacheKey(originalLocator, context);
this.cache.set(cacheKey, healedLocator);
}
generateCacheKey(originalLocator, context) {
const { testFile, lineNumber } = context;
return `${testFile}:${lineNumber}:${originalLocator}`;
}
async clearCache() {
this.cache.flushAll();
}
getStats() {
const stats = this.cache.getStats();
return {
hits: stats.hits,
misses: stats.misses,
keys: stats.keys
};
}
}
exports.LocatorCache = LocatorCache;