donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
108 lines • 3.84 kB
TypeScript
import type { Locator, Page } from 'playwright-core';
import { z } from 'zod/v4';
import type { DonobuExtendedPage } from '../../page/DonobuExtendedPage';
import type { LocateResult } from '../locate/locateTypes';
/**
* A single structured assertion step returned by the AI. Each step maps
* deterministically to one Playwright `expect` call — no free-form code
* generation, no VM evaluation.
*/
export declare const PlaywrightAssertionStepSchema: z.ZodObject<{
locator: z.ZodNullable<z.ZodEnum<{
text: "text";
role: "role";
label: "label";
}>>;
role: z.ZodNullable<z.ZodString>;
value: z.ZodString;
valueIsRegex: z.ZodBoolean;
assertion: z.ZodEnum<{
toBeVisible: "toBeVisible";
toBeHidden: "toBeHidden";
toBeEnabled: "toBeEnabled";
toBeDisabled: "toBeDisabled";
toBeChecked: "toBeChecked";
toHaveValue: "toHaveValue";
toContainText: "toContainText";
toHaveAttribute: "toHaveAttribute";
toHaveTitle: "toHaveTitle";
toHaveURL: "toHaveURL";
}>;
attributeValue: z.ZodNullable<z.ZodString>;
}, z.core.$strip>;
export type PlaywrightAssertionStep = z.infer<typeof PlaywrightAssertionStepSchema>;
export type AssertCacheExecutor = (context: {
page: Page;
/**
* Optional env mapping used to interpolate `{{$.env.X}}` placeholders that
* the AI may have embedded into step `value`/`attributeValue` fields. When
* absent, steps run unchanged (backwards compatible with cache entries
* recorded before env-aware caching).
*/
envData?: Record<string, string>;
}) => Promise<void>;
/**
* Builds an executor function from structured assertion steps.
* Each step maps to exactly one Playwright `expect` call — no string
* evaluation, no VM contexts.
*/
export declare function buildAssertExecutor(steps: PlaywrightAssertionStep[]): AssertCacheExecutor;
/**
* Cache key for a single `page.ai.assert(...)` invocation.
* Keyed on page hostname + assertion text so that the same assertion
* on the same domain always resolves to the same cached entry.
*/
export type AssertCacheKey = {
pageUrl: string;
assertion: string;
};
/**
* Serialised cache entry stored on disk. Contains structured assertion
* steps rather than raw code strings.
*/
export type AssertCacheEntry = AssertCacheKey & {
steps: PlaywrightAssertionStep[];
};
/**
* Entry hydrated with an executable runner.
*/
export type AssertCacheEntryWithRunner = AssertCacheEntry & {
run: AssertCacheExecutor;
};
/**
* Cache key for a single `page.ai.locate(...)` invocation.
* Keyed on page hostname + description text.
*/
export type LocateCacheKey = {
pageUrl: string;
description: string;
};
/**
* Serialised cache entry stored on disk. Contains the structured
* {@link LocateResult} that can be mechanically rebuilt into a Locator.
*/
export type LocateCacheEntry = LocateCacheKey & {
result: LocateResult;
};
/**
* Entry hydrated with an executable runner that returns a Locator.
*/
export type LocateCacheEntryWithRunner = LocateCacheEntry & {
run: LocateCacheExecutor;
};
export type LocateCacheExecutor = (context: {
page: DonobuExtendedPage;
/**
* Optional env mapping used to interpolate `{{$.env.X}}` placeholders that
* the AI may have embedded into `LocatorStep.text`/`name`/`testId` fields.
* Absent → steps run unchanged (backwards compatible with cache entries
* recorded before env-aware caching).
*/
envData?: Record<string, string>;
}) => Locator;
/**
* Builds a cache executor that mechanically reconstructs a Playwright
* {@link Locator} from a cached {@link LocateResult}.
*/
export declare function buildLocateExecutor(result: LocateResult): LocateCacheExecutor;
//# sourceMappingURL=assertCache.d.ts.map