magnitude-core
Version:
Magnitude e2e testing agent
56 lines (55 loc) • 2.08 kB
TypeScript
import { Page } from 'playwright';
export interface ImageDiff {
/** Difference score between 0-1, where 0 means identical */
difference: number;
/** Optional error message if comparison failed */
error?: string;
}
export interface PageStabilityOptions {
/** Threshold below which screenshots are considered similar (0-1) */
differenceThreshold?: number;
/** Number of consecutive stable checks required to confirm stability */
requiredStableChecks?: number;
/** Interval between stability checks in ms */
checkInterval?: number;
/** Whether to log detailed stability information */
/** Minimum time to wait before getting page state */
minimumWaitPageLoadTime?: number;
/** Time to wait for network requests to finish before getting page state */
waitForNetworkIdleTime?: number;
/** Maximum time to wait for page load before proceeding anyway */
maximumWaitPageLoadTime?: number;
}
/**
* Utility class to check for visual stability of a page
*/
export declare class PageStabilityAnalyzer {
private page;
private options;
private lastStart;
private logger;
constructor(options?: PageStabilityOptions);
setActivePage(page: Page): void;
private log;
/**
* Compare two screenshots and return their difference score
* @returns Difference as float between 0-1, where 0 means identical
*/
private compareScreenshots;
/**
* Wait for the network to become stable
* This monitors network requests and waits until there's a period of inactivity
* @param timeout Maximum time to wait for network stability
*/
waitForNetworkStability(timeout?: number): Promise<void>;
/**
* Wait for the page to become visually stable
* @param timeout Maximum time to wait for stability in ms
*/
waitForVisualStability(timeout?: number): Promise<void>;
/**
* Wait for both network and visual stability
* @param timeout Maximum time to wait for page load
*/
waitForStability(timeout?: number): Promise<void>;
}