import { Browser } from 'playwright'; import pino from 'pino'; interface Screenshot { image: string; dimensions: { width: number; height: number; }; } type WebAction = NavigateWebAction | ClickWebAction | TypeWebAction | ScrollWebAction; interface NavigateWebAction { variant: 'load'; url: string; } interface ClickWebAction { variant: 'click'; x: number; y: number; } interface TypeWebAction { variant: 'type'; x: number; y: number; content: string; } interface ScrollWebAction { variant: 'scroll'; x: number; y: number; deltaX: number; deltaY: number; } interface PixelCoordinate { x: number; y: number; } /** * "Ingredients" are natural language descriptors that align 1:1 with executable web actions. * Micro converts ingredients into web actions. */ type ActionIngredient = ClickIngredient | TypeIngredient | ScrollIngredient$1; type Ingredient = ActionIngredient | CheckIngredient; interface ClickIngredient { variant: 'click'; target: string; } interface TypeIngredient { variant: 'type'; target: string; content: string; } interface ScrollIngredient$1 { variant: 'scroll'; target: string; deltaX: number; deltaY: number; } interface CheckIngredient { variant: 'check'; description: string; } interface ScrollIngredient { variant: "scroll"; target: string; deltaX: number; deltaY: number; } type ActionVariant = 'load' | 'click' | 'hover' | 'type' | 'scroll' | 'wait' | 'back'; type ActionDescriptor = NavigateActionDescriptor | ClickActionDescriptor | TypeActionDescriptor | ScrollActionDescriptor; type NavigateActionDescriptor = NavigateWebAction & { screenshot: string; }; type ClickActionDescriptor = ClickIngredient & ClickWebAction & { screenshot: string; }; type TypeActionDescriptor = TypeIngredient & TypeWebAction & { screenshot: string; }; type ScrollActionDescriptor = ScrollIngredient & ScrollWebAction & { screenshot: string; }; interface TestAgentListener { onStart?: (testCase: TestCaseDefinition, runMetadata: Record) => void; onActionTaken?: (action: ActionDescriptor) => void; onStepCompleted?: () => void; onCheckCompleted?: () => void; onDone?: (result: TestCaseResult) => void; } /** * Represents any reason why a test case could have failed, for example: * - Step could not be completed * - Check did not pass * - Could not navigate to starting URL * - Time or action based timeout * - ... */ type FailureDescriptor = BugDetectedFailure | MisalignmentFailure | NetworkFailure | BrowserFailure | UnknownFailure; type BugSeverity = 'critical' | 'high' | 'medium' | 'low'; /** * Step and check failures are classified into one of: * BugDetectedFailure: seems to be something wrong with the application itself * MisalignmentFailure: seems to be a discrepency between the test case and the interface * OR the agent did not properly recognize the relationship between test case and interface */ interface BugDetectedFailure { variant: 'bug'; title: string; expectedResult: string; actualResult: string; severity: BugSeverity; } interface MisalignmentFailure { /** * Major misalignment: when a step/check fails due to: * 1. Poorly written step/check that is completely unrelated to the interface * 2. Or interface has changed so much that step/check no longer applicable * 3. Planner did not do good enough job adjusting recipe for minor misalignment * Misalignment could be due to a poorly written test case OR bad agent behavior. */ variant: 'misalignment'; message: string; } interface NetworkFailure { /** * For example, failure to connect to starting URL, or any other network errors * that would completely prevent the test from executing. */ variant: 'network'; message: string; } interface BrowserFailure { /** * E.g. something goes wrong with playwright interactions, any DOM manipulation, etc. */ variant: 'browser'; message: string; } interface UnknownFailure { variant: 'unknown'; message: string; } interface TestStepState { definition: TestStepDefinition; actions: ActionDescriptor[]; } interface TestCaseState { steps: TestStepState[]; stepIndex: number; checkIndex: number; result: TestCaseResult | null; metadata: Record; } declare function isTestCaseCompletedSuccessfully(state: TestCaseState): boolean; declare function isTestCaseDone(state: TestCaseState): boolean; declare function isTestCaseFailed(state: TestCaseState): boolean; declare class TestCaseStateTracker { private definition; private state; private stateSubscribers; constructor(testCase: TestCaseDefinition); getListener(): TestAgentListener; getState(): TestCaseState; onStateChange(callback: (state: TestCaseState) => void): void; private _notifyStateSubscribers; private _onStart; private _onActionTaken; private _onStepCompleted; private _onCheckCompleted; private _onDone; } declare function describeAction(action: ActionDescriptor): string; interface TestDataEntry { key: string; value: string; sensitive: boolean; } interface TestData { data?: TestDataEntry[]; other?: string; } interface TestStepDefinition { description: string; checks: string[]; testData: TestData; } interface TestCaseDefinition { url: string; steps: TestStepDefinition[]; recipe?: Ingredient[]; } type TestCaseResult = SuccessfulTestCaseResult | FailedTestCaseResult; interface SuccessfulTestCaseResult { passed: true; recipe: Ingredient[]; } interface FailedTestCaseResult { passed: false; failure: FailureDescriptor; } interface TestCaseAgentConfig { listeners: TestAgentListener[]; plannerModelProvider: 'SonnetBedrock' | 'SonnetAnthropic'; } declare class TestCaseAgent { private config; private listeners; private macro; private micro; private analytics; constructor(config?: Partial); run(browser: Browser, testCase: TestCaseDefinition): Promise; private _run; } declare const logger: pino.Logger; export { type ActionDescriptor, type ActionIngredient, type ActionVariant, type BrowserFailure, type BugDetectedFailure, type BugSeverity, type CheckIngredient, type ClickActionDescriptor, type ClickIngredient, type ClickWebAction, type FailedTestCaseResult, type FailureDescriptor, type Ingredient, type MisalignmentFailure, type NavigateActionDescriptor, type NavigateWebAction, type NetworkFailure, type PixelCoordinate, type Screenshot, type ScrollActionDescriptor, type ScrollIngredient$1 as ScrollIngredient, type ScrollWebAction, type SuccessfulTestCaseResult, type TestAgentListener, TestCaseAgent, type TestCaseDefinition, type TestCaseResult, type TestCaseState, TestCaseStateTracker, type TestData, type TestDataEntry, type TestStepDefinition, type TestStepState, type TypeActionDescriptor, type TypeIngredient, type TypeWebAction, type UnknownFailure, type WebAction, describeAction, isTestCaseCompletedSuccessfully, isTestCaseDone, isTestCaseFailed, logger };