fix: implement log scale back-off for screenshots (#12504)

References https://github.com/microsoft/playwright/issues/12441
This commit is contained in:
Andrey Lushnikov 2022-03-04 19:17:57 -07:00 committed by GitHub
parent 4953fc4845
commit 6dac01aec7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -1058,7 +1058,7 @@ export class Frame extends SdkObject {
});
}
async rafrafTimeoutScreenshotElementWithProgress(progress: Progress, selector: string, timeout: number, options: ScreenshotOptions): Promise<Buffer|undefined> {
async rafrafTimeoutScreenshotElementWithProgress(progress: Progress, selector: string, timeout: number, options: ScreenshotOptions): Promise<Buffer> {
return await this._retryWithProgressIfNotConnected(progress, selector, true /* strict */, async handle => {
await handle._frame.rafrafTimeout(timeout);
return await this._page._screenshotter.screenshotElement(progress, handle, options);

View file

@ -461,21 +461,21 @@ export class Page extends SdkObject {
return controller.run(async progress => {
let actual: Buffer | undefined;
let previous: Buffer | undefined;
let screenshotTimeout = 0;
const pollIntervals = [0, 100, 250, 500];
while (true) {
progress.throwIfAborted();
if (this.isClosed())
throw new Error('The page has closed');
let comparatorResult: ComparatorResult | undefined;
const screenshotTimeout = pollIntervals.shift() || 1000;
if (isGeneratingNewScreenshot) {
previous = actual;
actual = await rafrafScreenshot(progress, screenshotTimeout);
actual = await rafrafScreenshot(progress, screenshotTimeout).catch(e => undefined);
comparatorResult = actual && previous ? comparator(actual, previous, options.comparatorOptions) : undefined;
} else {
actual = await rafrafScreenshot(progress, screenshotTimeout);
actual = await rafrafScreenshot(progress, screenshotTimeout).catch(e => undefined);
comparatorResult = actual ? comparator(actual, options.expected!, options.comparatorOptions) : undefined;
}
screenshotTimeout = 150;
if (comparatorResult !== undefined && !!comparatorResult === !!options.isNot)
break;
if (comparatorResult)