playwright-advanced-ml-healer
Version:
Advanced AI-powered self-healing selectors for Playwright with 19+ healing types, neural networks, machine learning models, and Global DOM Learning ML Model
527 lines • 16.2 kB
TypeScript
import { Page, Locator, ElementHandle, Frame, Response, Request, ConsoleMessage, Dialog, Download, FileChooser, Worker, ViewportSize } from 'playwright';
interface WaitForSelectorOptions {
timeout?: number;
state?: 'attached' | 'detached' | 'visible' | 'hidden';
}
interface FillOptions {
timeout?: number;
force?: boolean;
noWaitAfter?: boolean;
}
interface TypeOptions {
timeout?: number;
delay?: number;
noWaitAfter?: boolean;
}
interface PressOptions {
timeout?: number;
delay?: number;
noWaitAfter?: boolean;
}
interface ClickOptions {
timeout?: number;
button?: 'left' | 'right' | 'middle';
clickCount?: number;
delay?: number;
force?: boolean;
modifiers?: ('Alt' | 'Control' | 'Meta' | 'Shift')[];
noWaitAfter?: boolean;
position?: {
x: number;
y: number;
};
trial?: boolean;
}
interface DblclickOptions {
timeout?: number;
button?: 'left' | 'right' | 'middle';
delay?: number;
force?: boolean;
modifiers?: ('Alt' | 'Control' | 'Meta' | 'Shift')[];
noWaitAfter?: boolean;
position?: {
x: number;
y: number;
};
trial?: boolean;
}
interface HoverOptions {
timeout?: number;
force?: boolean;
modifiers?: ('Alt' | 'Control' | 'Meta' | 'Shift')[];
position?: {
x: number;
y: number;
};
trial?: boolean;
}
interface CheckOptions {
timeout?: number;
force?: boolean;
noWaitAfter?: boolean;
position?: {
x: number;
y: number;
};
trial?: boolean;
}
interface UncheckOptions {
timeout?: number;
force?: boolean;
noWaitAfter?: boolean;
position?: {
x: number;
y: number;
};
trial?: boolean;
}
interface SelectOptionOptions {
timeout?: number;
force?: boolean;
noWaitAfter?: boolean;
}
interface DispatchEventOptions {
timeout?: number;
}
interface ScreenshotOptions {
timeout?: number;
type?: 'png' | 'jpeg';
path?: string;
quality?: number;
fullPage?: boolean;
clip?: {
x: number;
y: number;
width: number;
height: number;
};
omitBackground?: boolean;
}
interface PDFOptions {
timeout?: number;
path?: string;
format?: 'Letter' | 'Legal' | 'Tabloid' | 'Ledger' | 'A0' | 'A1' | 'A2' | 'A3' | 'A4' | 'A5' | 'A6';
printBackground?: boolean;
margin?: {
top?: string;
right?: string;
bottom?: string;
left?: string;
};
preferCSSPageSize?: boolean;
generateTaggedPDF?: boolean;
tagPDF?: boolean;
}
interface ExtraHTTPHeaders {
[key: string]: string;
}
interface LocatorOptions {
hasText?: string | RegExp;
has?: Locator;
}
/**
* PlaywrightCompatibleHealingPage - A drop-in replacement for Playwright's Page object
*
* This class provides all the standard Playwright Page methods with automatic
* selector healing capabilities. Users can simply replace their Page instances
* with this class and get automatic healing without changing any method names.
*
* Features:
* - 100% Playwright API compatibility
* - Automatic selector healing with 17+ strategies
* - Performance monitoring and analytics
* - Intelligent caching and fallbacks
* - Zero code changes required
*
* Usage:
* ```typescript
* // Before (Traditional Playwright)
* const page = await browser.newPage();
* await page.fill('#email', 'user@example.com');
*
* // After (With Advanced ML Healing)
* const page = await browser.newPage();
* const healingPage = new PlaywrightCompatibleHealingPage(page);
* await healingPage.fill('#emai', 'user@example.com'); // Automatically healed!
* ```
*/
export declare class PlaywrightCompatibleHealingPage {
private page;
private advancedML;
private healingStats;
private healedSelectors;
private fallbackSelectors;
private locatorHandlers;
constructor(page: Page);
/**
* Navigate to a URL with automatic retry and healing
*/
goto(url: string, options?: {
timeout?: number;
waitUntil?: 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
}): Promise<Response | null>;
/**
* Reload the page with automatic retry and healing
*/
reload(options?: {
timeout?: number;
waitUntil?: 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
}): Promise<Response | null>;
/**
* Click an element with automatic selector healing
*/
click(selector: string, options?: ClickOptions): Promise<void>;
/**
* Fill an input field with automatic selector healing
*/
fill(selector: string, value: string, options?: FillOptions): Promise<void>;
/**
* Type text into an element with automatic selector healing
*/
type(selector: string, text: string, options?: TypeOptions): Promise<void>;
/**
* Press a key with automatic selector healing
*/
press(selector: string, key: string, options?: PressOptions): Promise<void>;
/**
* Check a checkbox with automatic selector healing
*/
check(selector: string, options?: CheckOptions): Promise<void>;
/**
* Uncheck a checkbox with automatic selector healing
*/
uncheck(selector: string, options?: UncheckOptions): Promise<void>;
/**
* Select an option with automatic selector healing
*/
selectOption(selector: string, values: string | string[] | {
value?: string;
label?: string;
index?: number;
} | {
value?: string;
label?: string;
index?: number;
}[], options?: SelectOptionOptions): Promise<string[]>;
/**
* Hover over an element with automatic selector healing
*/
hover(selector: string, options?: HoverOptions): Promise<void>;
/**
* Focus on an element with automatic selector healing
*/
focus(selector: string, options?: {
timeout?: number;
}): Promise<void>;
/**
* Double-click an element with automatic selector healing
*/
dblclick(selector: string, options?: DblclickOptions): Promise<void>;
/**
* Drag and drop with automatic selector healing and element validation
*/
dragAndDrop(source: string, target: string, options?: {
timeout?: number;
force?: boolean;
}): Promise<void>;
/**
* Dispatch custom events with automatic selector healing
*/
dispatchEvent(selector: string, type: string, eventInit?: any, options?: DispatchEventOptions): Promise<void>;
/**
* Set input files with automatic selector healing
*/
setInputFiles(selector: string, files: string | string[] | FilePayload | FilePayload[], options?: {
timeout?: number;
noWaitAfter?: boolean;
}): Promise<void>;
/**
* Add custom locator handler (custom implementation)
*/
addLocatorHandler(selector: string, handler: (element: ElementHandle<Element>) => Promise<void>): Promise<void>;
/**
* Remove custom locator handler (custom implementation)
*/
removeLocatorHandler(selector: string): Promise<void>;
/**
* Add initialization script
*/
addInitScript(script: string | ((arg?: any) => any), arg?: any): Promise<void>;
/**
* Add style tag
*/
addStyleTag(options?: {
url?: string;
path?: string;
content?: string;
}): Promise<ElementHandle<Element>>;
/**
* Add script tag
*/
addScriptTag(options?: {
url?: string;
path?: string;
content?: string;
type?: string;
}): Promise<ElementHandle<Element>>;
/**
* Route network requests
*/
route(url: string | RegExp | ((route: any) => boolean), handler: ((route: any) => void)): Promise<void>;
/**
* Unroute network requests
*/
unroute(url: string | RegExp | ((route: any) => boolean), handler?: ((route: any) => void)): Promise<void>;
/**
* Expose function to page
*/
exposeFunction(name: string, callback: (arg?: any) => any): Promise<void>;
/**
* Expose binding to page
*/
exposeBinding(name: string, callback: (source: any, ...args: any[]) => any): Promise<void>;
/**
* Get a single element with automatic selector healing
*/
$(selector: string): Promise<ElementHandle<Element> | null>;
/**
* Get multiple elements with automatic selector healing
*/
$$(selector: string): Promise<ElementHandle<Element>[]>;
/**
* Wait for selector with automatic selector healing
*/
waitForSelector(selector: string, options?: WaitForSelectorOptions): Promise<ElementHandle<Element> | null>;
/**
* Get text content with automatic selector healing
*/
textContent(selector: string): Promise<string | null>;
/**
* Get inner text with automatic selector healing
*/
innerText(selector: string): Promise<string>;
/**
* Get inner HTML with automatic selector healing
*/
innerHTML(selector: string): Promise<string>;
/**
* Get outer HTML with automatic selector healing
*/
outerHTML(selector: string): Promise<string>;
/**
* Get attribute with automatic selector healing
*/
getAttribute(selector: string, name: string): Promise<string | null>;
/**
* Check if element is visible with automatic selector healing
*/
isVisible(selector: string): Promise<boolean>;
/**
* Blur an element (custom implementation since Playwright doesn't have this)
*/
blur(selector: string, options?: {
timeout?: number;
}): Promise<void>;
/**
* Get current URL
*/
getUrl(): Promise<string>;
/**
* Get page title
*/
getTitle(): Promise<string>;
/**
* Get viewport size
*/
getViewportSize(): Promise<ViewportSize>;
/**
* Check if page is closed
*/
isClosed(): Promise<boolean>;
/**
* Take screenshot
*/
screenshot(options?: ScreenshotOptions): Promise<Buffer>;
/**
* Generate PDF
*/
pdf(options?: PDFOptions): Promise<Buffer>;
/**
* Close page with enhanced cleanup
*/
close(options?: {
runBeforeUnload?: boolean;
}): Promise<void>;
/**
* Pause execution with enhanced debugging information
*/
pause(): Promise<void>;
/**
* Set viewport size
*/
setViewportSize(viewportSize: ViewportSize): Promise<void>;
/**
* Set extra HTTP headers with healing context
*/
setExtraHTTPHeaders(headers: ExtraHTTPHeaders): Promise<void>;
/**
* Set default timeout with healing context
*/
setDefaultTimeout(timeout: number): Promise<void>;
/**
* Set default navigation timeout with healing context
*/
setDefaultNavigationTimeout(timeout: number): Promise<void>;
/**
* Evaluate JavaScript on page with enhanced error handling
*/
evaluate<R, Arg>(pageFunction: ((arg?: Arg) => R) | string, arg?: Arg): Promise<R>;
/**
* Wait for load state
*/
waitForLoadState(state?: 'load' | 'domcontentloaded' | 'networkidle', options?: {
timeout?: number;
}): Promise<void>;
/**
* Wait for URL
*/
waitForURL(url: string | RegExp, options?: {
waitUntil?: 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
timeout?: number;
}): Promise<void>;
/**
* Wait for function
*/
waitForFunction(pageFunction: ((arg?: any) => any) | string, arg?: any, options?: {
timeout?: number;
polling?: number | 'raf';
}): Promise<any>;
/**
* Wait for response
*/
waitForResponse(urlOrPredicate: string | RegExp | ((response: Response) => boolean | Promise<boolean>), options?: {
timeout?: number;
}): Promise<Response>;
/**
* Wait for request
*/
waitForRequest(urlOrPredicate: string | RegExp | ((request: Request) => boolean | Promise<boolean>), options?: {
timeout?: number;
}): Promise<Request>;
/**
* Wait for specific events with enhanced options
*/
waitForEvent(event: 'console' | 'dialog' | 'download' | 'filechooser' | 'frameattached' | 'framedetached' | 'framenavigated' | 'load' | 'pageerror' | 'popup' | 'request' | 'requestfailed' | 'response' | 'worker', optionsOrPredicate?: {
timeout?: number;
} | ((...args: any[]) => boolean | Promise<boolean>)): Promise<any>;
/**
* Expect specific events with enhanced error handling
*/
expectEvent(event: 'console' | 'dialog' | 'download' | 'filechooser' | 'frameattached' | 'framedetached' | 'framenavigated' | 'load' | 'pageerror' | 'popup' | 'request' | 'requestfailed' | 'response' | 'worker', optionsOrPredicate?: {
timeout?: number;
} | ((...args: any[]) => boolean | Promise<boolean>)): Promise<any>;
/**
* Expect console messages with enhanced filtering
*/
expectConsoleMessage(optionsOrPredicate?: {
timeout?: number;
} | ((message: ConsoleMessage) => boolean | Promise<boolean>)): Promise<ConsoleMessage>;
/**
* Expect dialog popups with enhanced handling
*/
expectDialog(optionsOrPredicate?: {
timeout?: number;
} | ((dialog: Dialog) => boolean | Promise<boolean>)): Promise<Dialog>;
/**
* Expect file downloads with enhanced monitoring
*/
expectDownload(optionsOrPredicate?: {
timeout?: number;
} | ((download: Download) => boolean | Promise<boolean>)): Promise<Download>;
/**
* Expect file chooser with enhanced validation
*/
expectFileChooser(optionsOrPredicate?: {
timeout?: number;
} | ((fileChooser: FileChooser) => boolean | Promise<boolean>)): Promise<FileChooser>;
/**
* Expect popup windows with enhanced detection
*/
expectPopup(optionsOrPredicate?: {
timeout?: number;
} | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;
/**
* Expect network requests with enhanced monitoring
*/
expectRequest(optionsOrPredicate?: {
timeout?: number;
} | ((request: Request) => boolean | Promise<boolean>)): Promise<Request>;
/**
* Expect request completion with enhanced tracking
*/
expectRequestFinished(optionsOrPredicate?: {
timeout?: number;
} | ((request: Request) => boolean | Promise<boolean>)): Promise<Request>;
/**
* Expect network responses with enhanced validation
*/
expectResponse(optionsOrPredicate?: {
timeout?: number;
} | ((response: Response) => boolean | Promise<boolean>)): Promise<Response>;
/**
* Expect web workers with enhanced detection
*/
expectWorker(optionsOrPredicate?: {
timeout?: number;
} | ((worker: Worker) => boolean | Promise<boolean>)): Promise<Worker>;
/**
* Expect new pages with enhanced monitoring
*/
expectPage(optionsOrPredicate?: {
timeout?: number;
} | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;
/**
* Expect frame events with enhanced handling
*/
expectFrame(optionsOrPredicate?: {
timeout?: number;
} | ((frame: Frame) => boolean | Promise<boolean>)): Promise<Frame>;
/**
* Wait for timeout
*/
waitForTimeout(timeout: number): Promise<void>;
/**
* Create a locator with automatic selector healing
*/
locator(selector: string, options?: LocatorOptions): Locator;
/**
* Get or heal a selector for a specific action
*/
getOrHealSelector(selector: string, action: string): Promise<string>;
/**
* Get all healed selectors
*/
getHealedSelectors(): Map<string, string>;
/**
* Clear healed selectors
*/
clearHealedSelectors(): void;
/**
* Get healing statistics
*/
getHealingStats(): any;
/**
* Clear healing statistics
*/
clearHealingStats(): void;
private initializeFallbackSelectors;
private recordHealingSuccess;
private recordHealingFailure;
}
export interface FilePayload {
name: string;
mimeType: string;
buffer: Buffer;
}
export {};
//# sourceMappingURL=playwright-compatible-interface.d.ts.map