UNPKG

cucumber-ai

Version:

Write automated tests using natural language

62 lines 2.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UIAgent = void 0; const web_1 = require("@midscene/web"); class UIAgent { constructor(context) { this.context = context; } async start() { this.agent = new web_1.PlaywrightAgent(this.context.getDriver().page); this.registerActions(this.context.getActions()); } async stop() { this.unregisterActions(this.context.getActions()); this.agent = null; } async agentMethod(method, ...args) { await this.agent[method](...args); return { success: true }; } async ai(prompt, type) { return await this.agentMethod("ai", prompt, type); } async aiTap(locatePrompt, opt) { return await this.agentMethod("aiTap", locatePrompt, opt); } async aiInput(value, locatePrompt, opt) { return await this.agentMethod("aiInput", value, locatePrompt, opt); } async aiHover(locatePrompt, opt) { return await this.agentMethod("aiHover", locatePrompt, opt); } async aiKeyboardPress(key, locatePrompt, opt) { return await this.agentMethod("aiKeyboardPress", key, locatePrompt, opt); } async aiWaitFor(prompt, opt) { return await this.agentMethod("aiWaitFor", prompt, opt); } async aiAssert(assertion, msg, opt) { return await this.agentMethod("aiAssert", assertion, msg, opt); } registerActions(actions) { actions.register("ai", async (text) => await this.ai(text)); actions.register("aiTap", async (text) => await this.aiTap(text)); actions.register("aiInput", async (text, arg) => await this.aiInput(arg || "", text)); actions.register("aiHover", async (text) => await this.aiHover(text)); actions.register("aiWaitFor", async (text) => await this.aiWaitFor(text, { timeoutMs: 30000 })); actions.register("aiKeyboardPress", async (text) => await this.aiKeyboardPress(text)); actions.register("aiAssert", async (text) => await this.aiAssert(text)); } unregisterActions(actions) { actions.unregister("ai"); actions.unregister("aiTap"); actions.unregister("aiInput"); actions.unregister("aiHover"); actions.unregister("aiWaitFor"); actions.unregister("aiKeyboardPress"); actions.unregister("aiAssert"); } } exports.UIAgent = UIAgent; //# sourceMappingURL=index.js.map