UNPKG

@withkeystone/cli

Version:

Keystone CLI - Test automation for modern web apps

95 lines (82 loc) 2.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RECORDING_SCRIPT = void 0; exports.RECORDING_SCRIPT = ` (function() { // Avoid double injection if (window.__keystoneRecorder) return; window.__keystoneRecorder = { enabled: false, start() { this.enabled = true; this.attachListeners(); console.log('[Keystone] Recording started'); }, stop() { this.enabled = false; console.log('[Keystone] Recording stopped'); }, attachListeners() { // Click events document.addEventListener('click', (e) => { if (!this.enabled) return; const target = e.target; const selector = this.generateSelector(target); this.sendAction({ type: 'click', selector, text: target.textContent?.trim().substring(0, 50), position: { x: e.clientX, y: e.clientY } }); }, true); // Input events document.addEventListener('input', (e) => { if (!this.enabled) return; const target = e.target; if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') { this.sendAction({ type: 'type', selector: this.generateSelector(target), value: target.value }); } }, true); // Form submissions document.addEventListener('submit', (e) => { if (!this.enabled) return; this.sendAction({ type: 'submit', selector: this.generateSelector(e.target) }); }, true); }, generateSelector(element) { // Priority: id > data-testid > aria-label > class > tag if (element.id) return '#' + element.id; if (element.dataset.testid) return '[data-testid="' + element.dataset.testid + '"]'; if (element.getAttribute('aria-label')) return '[aria-label="' + element.getAttribute('aria-label') + '"]'; // Fallback to path const path = []; while (element && element.nodeType === Node.ELEMENT_NODE) { let selector = element.nodeName.toLowerCase(); if (element.className) { selector += '.' + element.className.split(' ').join('.'); } path.unshift(selector); element = element.parentNode; } return path.join(' > '); }, sendAction(action) { // Send to parent window (Studio) window.parent.postMessage({ source: 'keystone-recorder', action: action, url: window.location.href, timestamp: Date.now() }, '*'); } }; })(); `; //# sourceMappingURL=recorder.js.map