UNPKG

@labnex/cli

Version:

CLI for Labnex, an AI-Powered Testing Automation Platform

31 lines 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractHintedSelector = extractHintedSelector; const addLog_1 = require("./addLog"); // Returns the type ('xpath', 'css', etc.), the selector value, and the remaining part of the step. function extractHintedSelector(stepPart) { (0, addLog_1.addLog)(`[extractHintedSelector] Received stepPart: "${stepPart}"`); // First, check for xpath:// or css:// prefix format const prefixPattern = /^(xpath|css):\/\/(.+)$/i; const prefixMatch = stepPart.match(prefixPattern); if (prefixMatch && prefixMatch[1] && prefixMatch[2]) { const type = prefixMatch[1].toLowerCase(); const selectorValue = prefixMatch[2].trim(); (0, addLog_1.addLog)(`[extractHintedSelector] Prefix hint found. Type: "${type}", Raw Value: "${selectorValue}"`); return { type, selectorValue, remainingStep: '' }; } // Then check for (type: value) format const hintPattern = /^\s*\(\s*(\w+)\s*:\s*(.+?)\s*\)\s*$/i; const match = stepPart.match(hintPattern); if (match && match[1] && match[2]) { const type = match[1].toLowerCase(); const selectorValue = match[2].trim(); (0, addLog_1.addLog)(`[extractHintedSelector] Parentheses hint found. Type: "${type}", Raw Value: "${selectorValue}"`); const remainingStep = stepPart.replace(hintPattern, '').trim(); (0, addLog_1.addLog)(`[extractHintedSelector] Remaining step after hint extraction: "${remainingStep}"`); return { type, selectorValue, remainingStep }; } (0, addLog_1.addLog)(`[extractHintedSelector] No hint pattern matched in: "${stepPart}"`); return { remainingStep: stepPart.trim() }; } //# sourceMappingURL=extractHintedSelector.js.map