UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

143 lines 8 kB
import { TestFixture } from '@playwright/test'; import type { Page } from '@playwright/test'; import { FlowMetadata } from './models/FlowMetadata'; import { BrowserStorageState } from './models/BrowserStorageState'; import { BrowserStateReference } from './models/BrowserStateFlowReference'; import { ToolCallResult } from './models/ToolCallResult'; import { AnalyzePageTextToolCoreParameters } from './tools/AnalyzePageTextTool'; import { AssertToolCoreParameters } from './tools/AssertTool'; import { GptClient } from './clients/GptClient'; import { SelectorBasedChooseSelectOptionToolParameters } from './tools/ChooseSelectOptionTool'; import { SelectorBasedInputRandomizedEmailAddressToolParameters } from './tools/InputRandomizedEmailAddressTool'; import { SelectorBasedInputTextToolParameters } from './tools/InputTextTool'; import { SelectorBasedPressKeyToolParameters } from './tools/PressKeyTool'; import { ScrollPageToolCoreParameters } from './tools/ScrollPageTool'; import { SelectorBasedHoverOverElementToolParameters } from './tools/HoverOverElementTool'; import { SelectorBasedClickToolParameters } from './tools/ClickTool'; import { LanguageModel } from 'ai'; import { AssertPageTextToolCoreParameters } from './tools/AssertPageTextTool'; import { DonobuStack } from './managers/DonobuStack'; import { JSONSchema7 } from 'json-schema'; /** * Extends the Page object with additional test-related methods. */ interface DonobuExtendedPage extends Page { /** * Run an arbitrary Donobu tool by name. */ run(toolName: string, toolParams?: any): Promise<ToolCallResult>; /** * Run an analysis on the current webpage's full raw text. Note that since this runs an analysis on the raw text, * rather than, the HTML of the page, the raw text may be a bit jumbled, have its styling lost, careful * positioning lost, etc. This tool is useful if there happens to be a lot of text on a page, and it would be * tedious to scroll through the entirety of the page in order to get enough context to run an analysis. * * If there is context relevant to running the analysis that would not be found in the webpage text itself, * perhaps context given in another message, prompt, overall object, etc, then provide it in the * "additionalRelevantContext" parameter. */ analyzePageText(params: AnalyzePageTextToolCoreParameters): Promise<ToolCallResult>; /** * Assert that given text is visible in the current page. */ assertPageText(params: AssertPageTextToolCoreParameters): Promise<ToolCallResult>; /** * Choose <option> values for a particular <select> HTML element. */ chooseSelectOption(params: SelectorBasedChooseSelectOptionToolParameters): Promise<ToolCallResult>; /** * Click an element on a webpage. */ clickElement(params: SelectorBasedClickToolParameters): Promise<ToolCallResult>; /** * Perform an analysis of the cookies for the current web browsing session. */ createCookieReport(): Promise<ToolCallResult>; /** * Return an object conforming to the given JSON-schema. The object will be * generated considering the following: * - The given instruction (if any). * - A screenshot of the current state of the page. * - The history of actions taken on the page. */ extract(params: { instruction?: string; schema: JSONSchema7; }): Promise<Record<string, unknown>>; /** * Hover the mouse over a specified element on a webpage. */ hoverOverElement(params: SelectorBasedHoverOverElementToolParameters): Promise<ToolCallResult>; /** * Create a new randomized email address based on a given email and inputs it to a specific input text field. * For example if passed "foo@gmail.com", this tool will create "foo+SOMETHING_RANDOM@gmail.com", where * SOMETHING_RANDOM is a random string of characters safe for use in an email address, and input it in the * specified text field. */ inputRandomizedEmailAddress(params: SelectorBasedInputRandomizedEmailAddressToolParameters): Promise<ToolCallResult>; /** * Input text to a webpage's text input box. */ inputText(params: SelectorBasedInputTextToolParameters): Promise<ToolCallResult>; /** * Press a single key. Note that if there is existing text in the element, it is appended rather than cleared. * * Generally, prefer using the 'inputText' tool instead as it automatically clears existing text * and it allows the input of multiple characters at a time. The only advantage this tool has is * that it allows the passing of control keys like "Tab", "Backspace", etc. */ pressKey(params: SelectorBasedPressKeyToolParameters): Promise<ToolCallResult>; /** * Run an web accessibility (i.e. axe-core) test on the current webpage. */ runAccessibilityTest(): Promise<ToolCallResult>; /** * Scroll the current page up or down by one viewport. */ scroll(params: ScrollPageToolCoreParameters): Promise<ToolCallResult>; /** * Visually assert that a given condition (i.e. the 'assertionToTestFor' field) holds true, using a screenshot of * the current webpage. */ visuallyAssert(params: AssertToolCoreParameters): Promise<ToolCallResult>; _donobuFlowMetadata: FlowMetadata; } export declare function getOrCreateDonobuStack(): Promise<DonobuStack>; export declare function getBrowserStorageState(flowIdOrName: BrowserStateReference): Promise<BrowserStorageState>; export declare function getBrowserStorageStateFixture(flowIdOrName: BrowserStateReference): TestFixture<BrowserStorageState, any>; export declare function anthropicClient(modelName: string, apiKey?: string): Promise<GptClient>; export declare function anthropicClientFixture(modelName: string, apiKey?: string): TestFixture<GptClient, any>; export declare function anthropicAwsBedrockClient(modelName: string, region: string, accessKeyId?: string, secretAccessKey?: string): Promise<GptClient>; export declare function anthropicAwsBedrockClientFixture(modelName: string, region: string, accessKeyId?: string, secretAccessKey?: string): TestFixture<GptClient, any>; export declare function googleGeminiClient(modelName: string, apiKey?: string): Promise<GptClient>; export declare function googleGeminiClientFixture(modelName: string, apiKey?: string): TestFixture<GptClient, any>; export declare function openAiClient(modelName: string, apiKey?: string): Promise<GptClient>; export declare function openAiClientFixture(modelName: string, apiKey?: string): TestFixture<GptClient, any>; export declare function vercelAiClientFixture(model: LanguageModel): TestFixture<GptClient, any>; /** * This fixture resolves a GPT client based on environment variables. * Supplying different environment variables will result in different GPT * clients being created. Here is a mapping of client type to environment * variables for how to create the various types of clients... * * Anthropic GPT client requires: * - ANTHROPIC_API_KEY * * Google GPT client requires: * - GOOGLE_GENERATIVE_AI_API_KEY * * OpenAI GPT client requires: * - OPENAI_API_KEY * * If the modelName is not specified, it will be defaulted according to the * DEFAULT_GPT_MODEL_FOR_PLATFORM mapping. */ export declare function gptClient(modelName?: string): Promise<GptClient>; export declare function gptClientFixture(modelName?: string): TestFixture<GptClient, any>; export * from 'playwright/test'; export declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & { storageState?: BrowserStorageState | Promise<BrowserStorageState>; gptClient?: GptClient; page: DonobuExtendedPage; }, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions>; //# sourceMappingURL=playwrightTestExtensions.d.ts.map