Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(rpc): handle screenshot path on the client (#3352)
Dmitry Gozman69c88d806302
diff --git a/src/rpc/channels.ts b/src/rpc/channels.tsindex 80c63b12d8..a872fc22ea 100644--- a/src/rpc/channels.ts+++ b/src/rpc/channels.ts@@ -911,7 +911,6 @@ export type PageReloadResult = {export type PageScreenshotParams = {timeout?: number,type?: 'png' | 'jpeg',- path?: string,quality?: number,omitBackground?: boolean,fullPage?: boolean,@@ -925,7 +924,6 @@ export type PageScreenshotParams = {export type PageScreenshotOptions = {timeout?: number,type?: 'png' | 'jpeg',- path?: string,quality?: number,omitBackground?: boolean,fullPage?: boolean,diff --git a/src/rpc/client/page.ts b/src/rpc/client/page.tsindex c58785f96f..820b155457 100644--- a/src/rpc/client/page.ts+++ b/src/rpc/client/page.ts@@ -422,9 +422,12 @@ export class Page extends ChannelOwner<PageChannel, PageInitializer> {});}- async screenshot(options: PageScreenshotOptions = {}): Promise<Buffer> {+ async screenshot(options: PageScreenshotOptions & { path?: string } = {}): Promise<Buffer> {return this._wrapApiCall('page.screenshot', async () => {- return Buffer.from((await this._channel.screenshot(options)).binary, 'base64');+ const buffer = Buffer.from((await this._channel.screenshot(options)).binary, 'base64');+ if (options.path)+ await fsWriteFileAsync(options.path, buffer);+ return buffer;});}@@ -541,10 +544,7 @@ export class Page extends ChannelOwner<PageChannel, PageInitializer> {}async _pdf(options: PDFOptions = {}): Promise<Buffer> {- const path = options.path;const transportOptions: PagePdfParams = { ...options } as PagePdfParams;- if (path)- delete (transportOptions as any).path;if (transportOptions.margin)transportOptions.margin = { ...transportOptions.margin };if (typeof options.width === 'number')@@ -558,8 +558,8 @@ export class Page extends ChannelOwner<PageChannel, PageInitializer> {}const result = await this._channel.pdf(transportOptions);const buffer = Buffer.from(result.pdf, 'base64');- if (path)- await fsWriteFileAsync(path, buffer);+ if (options.path)+ await fsWriteFileAsync(options.path, buffer);return buffer;}}diff --git a/src/rpc/protocol.yml b/src/rpc/protocol.ymlindex 7f68198a86..bada84e12e 100644--- a/src/rpc/protocol.yml+++ b/src/rpc/protocol.yml@@ -701,7 +701,6 @@ Page:literals:- png- jpeg- path: string?quality: number?omitBackground: boolean?fullPage: boolean?diff --git a/src/rpc/validator.ts b/src/rpc/validator.tsindex 1ed318194a..9f46fa68aa 100644--- a/src/rpc/validator.ts+++ b/src/rpc/validator.ts@@ -360,7 +360,6 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {scheme.PageScreenshotParams = tObject({timeout: tOptional(tNumber),type: tOptional(tEnum(['png', 'jpeg'])),- path: tOptional(tString),quality: tOptional(tNumber),omitBackground: tOptional(tBoolean),fullPage: tOptional(tBoolean),