@labnex/cli
Version:
CLI for Labnex, an AI-Powered Testing Automation Platform
29 lines • 1.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractDialogExpectation = extractDialogExpectation;
const addLog_1 = require("./addLog");
function extractDialogExpectation(step) {
const dialogHandlingPattern = /\s+and\s+(accept|dismiss)\s+(alert|confirm|confirmation|prompt)(?:\s+with\s+(['"])(.*?)\3)?$/i;
const dialogMatch = step.match(dialogHandlingPattern);
if (dialogMatch) {
(0, addLog_1.addLog)(`Dialog pattern matched: ${dialogMatch[0]}`);
const dialogAction = dialogMatch[1].toLowerCase();
let dialogType = dialogMatch[2].toLowerCase();
if (dialogType === 'confirmation')
dialogType = 'confirm';
const promptText = dialogMatch[4]; // Captured text for prompt
const expectation = {
type: dialogType,
response: dialogAction === 'accept' ? true : false,
};
if (dialogType === 'prompt' && dialogAction === 'accept' && promptText !== undefined) {
expectation.response = promptText;
}
const remainingStep = step.substring(0, step.length - dialogMatch[0].length).trim();
(0, addLog_1.addLog)(`Step after removing dialog phrase: "${remainingStep}"`);
return { expectation, remainingStep };
}
(0, addLog_1.addLog)("No dialog handling phrase found in step.");
return { remainingStep: step };
}
//# sourceMappingURL=extractDialogExpectation.js.map