donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
42 lines • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AssertPageTextTool = void 0;
const Tool_1 = require("./Tool");
const ToolCallResult_1 = require("../models/ToolCallResult");
class AssertPageTextTool extends Tool_1.Tool {
constructor() {
super(AssertPageTextTool.NAME, 'This method will test that the given text is visible in the current page.', 'AssertPageTextToolCoreParameters', 'AssertPageTextToolGptParameters', true);
}
async call(context, parameters) {
const locator = context.page.getByText(parameters.text);
const count = await locator.count();
const elementWasFoundWithText = count > 0;
for (let i = 0; i < count; ++i) {
const element = locator.nth(i);
await element.scrollIntoViewIfNeeded();
if (await element.isVisible()) {
return ToolCallResult_1.ToolCallResult.successful();
}
}
if (elementWasFoundWithText) {
return {
isSuccessful: false,
forLlm: `The text "${parameters.text}" was found in the page, but its containing element was not visible.`,
metadata: null,
};
}
else {
return {
isSuccessful: false,
forLlm: `Failed to find the text "${parameters.text}" anywhere in the page.`,
metadata: null,
};
}
}
async callFromGpt(context, parameters) {
return this.call(context, parameters);
}
}
exports.AssertPageTextTool = AssertPageTextTool;
AssertPageTextTool.NAME = 'assertPageText';
//# sourceMappingURL=AssertPageTextTool.js.map