///
import { Webdriver } from '../interfaces/webdriver';
import { PNGDiffer } from '../interfaces/png-differ';
import { ScreenshotStorage } from '../interfaces/screenshot-storage';
import { Screenshotter, ScreenshotOptions } from '../interfaces/screenshotter';
export interface MugshotIdenticalResult {
matches: true;
/**
* The name of the baseline.
*/
expectedName: string;
/**
* A PNG MIME encoded buffer of the baseline image.
*/
expected: Buffer;
}
export interface MugshotDiffResult {
matches: false;
/**
* A PNG MIME encoded buffer of the baseline image.
*/
expected: Buffer;
/**
* A PNG MIME encoded buffer of the actual screenshot.
*/
actual: Buffer;
/**
* A PNG MIME encoded buffer of the diff image.
*/
diff: Buffer;
/**
* The name of the baseline.
*/
expectedName: string;
/**
* The name of the actual screenshot.
*/
actualName: string;
/**
* The name of the diff image.
*/
diffName: string;
}
export declare type MugshotResult = MugshotIdenticalResult | MugshotDiffResult;
/**
* Identify an element on the screen. Depending on the {@link Screenshotter}
* implementation this could be a CSS selector, an iOS selector, an Android
* selector etc.
*
* NOTE: This abstraction produces a LISP violation: some {@link Screenshotter}
* implementations only work with a subset of selectors e.g. CSS selectors
* or iOS selectors. Fixing this would require inverting the dependency
* between {@link Mugshot} and {@link Screenshotter}, which I'm not fond of since it
* moves `Mugshot` one level down. WebdriverIO, for instance, has the same
* problem; it can talk to Appium which can talk to mobile devices, so using
* `'div'` as a selector doesn't make sense in that case.
*/
export declare type ElementSelector = string;
/**
* Identify a rectangle on the screen relative to the top left corner (0, 0).
*
* The `x` and `y` properties are named like that instead of `left` and `top`
* (that would match `width` and `height` in style) because it's meant to
* align with the builtin `DOMRect` type.
*/
export interface ElementRect {
x: number;
y: number;
width: number;
height: number;
}
export declare type MugshotSelector = ElementSelector | ElementRect;
export interface MugshotOptions {
pngDiffer?: PNGDiffer;
/**
* If set to `true` then `Mugshot.check` will pass if a baseline is not
* found and it will create the baseline from the screenshot it
* takes.
*/
createMissingBaselines?: boolean;
/**
* When set to `true` then `Mugshot.check` will overwrite any existing baselines
* and will create missing ones (implies setting
* `createMissingBaselines: true`).
*/
updateBaselines?: boolean;
}
export declare class MugshotMissingBaselineError extends Error {
constructor(name: string);
}
export declare class Mugshot {
private readonly pngDiffer;
private readonly storage;
private readonly screenshotter;
private readonly createMissingBaselines;
private readonly updateBaselines;
/**
* Set up Mugshot using sane defaults.
*
* If you need more complex options use the "advanced" form of the constructor.
*
* @param adapter A {@link Webdriver} implementation to be passed to
* {@link WebdriverScreenshotter}. If you need to pass in options to
* `WebdriverScreenshotter` then use the "advanced" Mugshot constructor.
* @param resultsPath A filesystem path where screenshots will be stored
* using {@link FsStorage}. If you need to pass in options to `FsStorage`
* then use the "advanced" Mugshot constructor.
* @param options
*/
constructor(adapter: Webdriver, resultsPath: string, options?: MugshotOptions);
/**
* Set up Mugshot in "advanced" mode where you can pass in options to the
* various subsystems or plug in your own.
*
* @param screenshotter
* @param storage
* @param options
*/
constructor(screenshotter: Screenshotter, storage: ScreenshotStorage, options?: MugshotOptions);
/**
* Check for visual regressions.
*
* @param name Mugshot will ask the storage implementation for a baseline
* with this name. If one is not found and `createMissingBaselines`
* is true then Mugshot will create a new baseline and return a passing
* result. Any leftover diffs from last time will be cleaned up.
*
* If a baseline is found then it will be compared with the screenshot
* taken from `screenshotter`. If differences are found this will return a
* failing result and a `${name}.diff` and a `${name}.actual` will be
* created using `storage`. If no differences are found then a passing
* result will be returned and any leftover diffs from last time will be
* cleaned up.
*
* @param selector See {@link Screenshotter.takeScreenshot} for more details.
*
* @param options
*/
check(name: string, selector: MugshotSelector, options?: ScreenshotOptions): Promise;
/**
* Check for visual regressions.
*
* @param name Mugshot will ask the storage implementation for a baseline
* with this name. If one is not found and `createMissingBaselines`
* is true then Mugshot will create a new baseline and return a passing
* result. Any leftover diffs from last time will be cleaned up.
*
* If a baseline is found then it will be compared with the screenshot
* taken from `screenshotter`. If differences are found this will return a
* failing result and a `${name}.diff` and a `${name}.actual` will be
* created using `storage`. If no differences are found then a passing
* result will be returned and any leftover diffs from last time will be
* cleaned up.
*
* @param options
*/
check(name: string, options?: ScreenshotOptions): Promise;
private writeBaseline;
private diff;
private getScreenshot;
private cleanup;
}