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(video): start/stop (#38991)
Dmitry Gozman917afdd93c56
diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.mdindex 55399a4d67..481a251deb 100644--- a/docs/src/api/class-page.md+++ b/docs/src/api/class-page.md@@ -4365,9 +4365,10 @@ Optional handler function to route the request.## method: Page.video* since: v1.8-- returns: <[null]|[Video]>+- returns: <[Video]>-Video object associated with this page.+Video object associated with this page. Can be used to control video recording with [`method: Video.start`]+and [`method: Video.stop`], or to access the video file when using the `recordVideo` context option.## method: Page.viewportSize* since: v1.8diff --git a/docs/src/api/class-video.md b/docs/src/api/class-video.mdindex 23eead4884..4dad21d483 100644--- a/docs/src/api/class-video.md+++ b/docs/src/api/class-video.md@@ -23,6 +23,38 @@ print(page.video.path())Console.WriteLine(await page.Video.GetPathAsync());```+Alternatively, you can use [`method: Video.start`] and [`method: Video.stop`] to record video manually. This approach is mutually exclusive with the `recordVideo` option.++```js+await page.video().start();+// ... perform actions ...+await page.video().stop({ path: 'video.webm' });+```++```java+page.video().start();+// ... perform actions ...+page.video().stop(new Video.StopOptions().setPath(Paths.get("video.webm")));+```++```python async+await page.video.start()+# ... perform actions ...+await page.video.stop(path="video.webm")+```++```python sync+page.video.start()+# ... perform actions ...+page.video.stop(path="video.webm")+```++```csharp+await page.Video.StartAsync();+// ... perform actions ...+await page.Video.StopAsync(new() { Path = "video.webm" });+```+## async method: Video.delete* since: v1.11@@ -58,3 +90,60 @@ Saves the video to a user-specified path. If using the sync API, this must be ca- `path` <[path]>Path where the video should be saved.+++## async method: Video.start+* since: v1.59++Starts video recording. This method is mutually exclusive with the `recordVideo` context option.++**Usage**++```js+await page.video().start();+// ... perform actions ...+await page.video().stop({ path: 'video.webm' });+```++```java+page.video().start();+// ... perform actions ...+page.video().stop(new Video.StopOptions().setPath(Paths.get("video.webm")));+```++```python async+await page.video.start()+# ... perform actions ...+await page.video.stop(path="video.webm")+```++```python sync+page.video.start()+# ... perform actions ...+page.video.stop(path="video.webm")+```++```csharp+await page.Video.StartAsync();+// ... perform actions ...+await page.Video.StopAsync(new() { Path = "video.webm" });+```++### option: Video.start.size+* since: v1.59+- `size` ?<[Object]>+ - `width` <[int]> Video frame width.+ - `height` <[int]> Video frame height.++Optional dimensions of the recorded video. If not specified the size will be equal to page viewport scaled down to fit into 800x800. Actual picture of the page will be scaled down if necessary to fit the specified size.++## async method: Video.stop+* since: v1.59++Stops video recording started with [`method: Video.start`] and either saves or discards the video file.++### option: Video.stop.path+* since: v1.59+- `path` <[path]>++Path where the video should be saved.diff --git a/packages/playwright-client/types/types.d.ts b/packages/playwright-client/types/types.d.tsindex 50dd490708..ba9b01d9da 100644--- a/packages/playwright-client/types/types.d.ts+++ b/packages/playwright-client/types/types.d.ts@@ -4802,9 +4802,12 @@ export interface Page {url(): string;/**- * Video object associated with this page.+ * Video object associated with this page. Can be used to control video recording with+ * [video.start([options])](https://playwright.dev/docs/api/class-video#video-start) and+ * [video.stop([options])](https://playwright.dev/docs/api/class-video#video-stop), or to access the video file when+ * using the `recordVideo` context option.*/- video(): null|Video;+ video(): Video;viewportSize(): null|{/**@@ -21757,6 +21760,16 @@ export interface Tracing {* console.log(await page.video().path());* ```*+ * Alternatively, you can use [video.start([options])](https://playwright.dev/docs/api/class-video#video-start) and+ * [video.stop([options])](https://playwright.dev/docs/api/class-video#video-stop) to record video manually. This+ * approach is mutually exclusive with the `recordVideo` option.+ *+ * ```js+ * await page.video().start();+ * // ... perform actions ...+ * await page.video().stop({ path: 'video.webm' });+ * ```+ **/export interface Video {/**@@ -21776,6 +21789,50 @@ export interface Video {* @param path Path where the video should be saved.*/saveAs(path: string): Promise<void>;++ /**+ * Starts video recording. This method is mutually exclusive with the `recordVideo` context option.+ *+ * **Usage**+ *+ * ```js+ * await page.video().start();+ * // ... perform actions ...+ * await page.video().stop({ path: 'video.webm' });+ * ```+ *+ * @param options+ */+ start(options?: {+ /**+ * Optional dimensions of the recorded video. If not specified the size will be equal to page viewport scaled down to+ * fit into 800x800. Actual picture of the page will be scaled down if necessary to fit the specified size.+ */+ size?: {+ /**+ * Video frame width.+ */+ width: number;++ /**+ * Video frame height.+ */+ height: number;+ };+ }): Promise<void>;++ /**+ * Stops video recording started with+ * [video.start([options])](https://playwright.dev/docs/api/class-video#video-start) and either saves or discards the+ * video file.+ * @param options+ */+ stop(options?: {+ /**+ * Path where the video should be saved.+ */+ path?: string;+ }): Promise<void>;}/**diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.tsindex adc7654de9..3750a936fb 100644--- a/packages/playwright-core/src/client/page.ts+++ b/packages/playwright-core/src/client/page.ts@@ -288,12 +288,10 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Pagereturn this._video;}- video(): Video | null {+ video(): Video {// Note: we are creating Video object lazily, because we do not know// BrowserContextOptions when constructing the page - it is assigned// too late during launchPersistentContext.- if (!this._browserContext._options.recordVideo)- return null;return this._forceVideo();}diff --git a/packages/playwright-core/src/client/video.ts b/packages/playwright-core/src/client/video.tsindex 1ff4065be7..ad3f767c4a 100644--- a/packages/playwright-core/src/client/video.ts+++ b/packages/playwright-core/src/client/video.ts@@ -15,19 +15,22 @@*/import { ManualPromise } from '../utils/isomorphic/manualPromise';+import { Artifact } from './artifact';-import type { Artifact } from './artifact';import type { Connection } from './connection';import type { Page } from './page';import type * as api from '../../types/types';export class Video implements api.Video {private _artifact: Promise<Artifact | null> | null = null;- private _artifactReadyPromise = new ManualPromise<Artifact>();+ private _artifactReadyPromise: ManualPromise<Artifact>;private _isRemote = false;+ private _page: Page;constructor(page: Page, connection: Connection) {+ this._page = page;this._isRemote = connection.isRemote();+ this._artifactReadyPromise = new ManualPromise<Artifact>();this._artifact = page._closedOrCrashedScope.safeRace(this._artifactReadyPromise);}@@ -35,6 +38,20 @@ export class Video implements api.Video {this._artifactReadyPromise.resolve(artifact);}+ async start(options: { size?: { width: number, height: number } } = {}): Promise<void> {+ await this._page._channel.videoStart(options);+ this._artifactReadyPromise = new ManualPromise<Artifact>();+ this._artifact = this._page._closedOrCrashedScope.safeRace(this._artifactReadyPromise);+ }++ async stop(options: { path?: string } = {}): Promise<void> {+ await this._page._wrapApiCall(async () => {+ await this._page._channel.videoStop();+ if (options.path)+ await this.saveAs(options.path);+ });+ }+async path(): Promise<string> {if (this._isRemote)throw new Error(`Path is not available when connecting remotely. Use saveAs() to save a local copy.`);diff --git a/packages/playwright-core/src/protocol/validator.ts b/packages/playwright-core/src/protocol/validator.tsindex bc253a5a7b..a8d1362b79 100644--- a/packages/playwright-core/src/protocol/validator.ts+++ b/packages/playwright-core/src/protocol/validator.ts@@ -1482,6 +1482,15 @@ scheme.PageStopCSSCoverageResult = tObject({});scheme.PageBringToFrontParams = tOptional(tObject({}));scheme.PageBringToFrontResult = tOptional(tObject({}));+scheme.PageVideoStartParams = tObject({+ size: tOptional(tObject({+ width: tInt,+ height: tInt,+ })),+});+scheme.PageVideoStartResult = tOptional(tObject({}));+scheme.PageVideoStopParams = tOptional(tObject({}));+scheme.PageVideoStopResult = tOptional(tObject({}));scheme.PageUpdateSubscriptionParams = tObject({event: tEnum(['console', 'dialog', 'fileChooser', 'request', 'response', 'requestFinished', 'requestFailed']),enabled: tBoolean,diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.tsindex f8d1f2507b..a345bbebb5 100644--- a/packages/playwright-core/src/server/browserContext.ts+++ b/packages/playwright-core/src/server/browserContext.ts@@ -745,28 +745,29 @@ export function validateBrowserContextOptions(options: types.BrowserContextOptiooptions.acceptDownloads = 'internal-browser-default';if (!options.viewport && !options.noDefaultViewport)options.viewport = { width: 1280, height: 720 };- if (options.recordVideo) {- if (!options.recordVideo.size) {- if (options.noDefaultViewport) {- options.recordVideo.size = { width: 800, height: 600 };- } else {- const size = options.viewport!;- const scale = Math.min(1, 800 / Math.max(size.width, size.height));- options.recordVideo.size = {- width: Math.floor(size.width * scale),- height: Math.floor(size.height * scale)- };- }- }- // Make sure both dimensions are odd, this is required for vp8- options.recordVideo.size!.width &= ~1;- options.recordVideo.size!.height &= ~1;- }+ if (options.recordVideo)+ options.recordVideo.size = validateVideoSize(options.recordVideo.size, options.viewport);if (options.proxy)options.proxy = normalizeProxySettings(options.proxy);verifyGeolocation(options.geolocation);}+export function validateVideoSize(size: types.Size | undefined, viewport: types.Size | undefined): types.Size {+ if (!size) {+ viewport ??= { width: 800, height: 600 };+ const scale = Math.min(1, 800 / Math.max(viewport.width, viewport.height));+ size = {+ width: Math.floor(viewport.width * scale),+ height: Math.floor(viewport.height * scale)+ };+ }+ // Make sure both dimensions are odd, this is required for vp8+ return {+ width: size.width & ~1,+ height: size.height & ~1+ };+}+export function verifyGeolocation(geolocation?: types.Geolocation): asserts geolocation is types.Geolocation {if (!geolocation)return;diff --git a/packages/playwright-core/src/server/chromium/crPage.ts b/packages/playwright-core/src/server/chromium/crPage.tsindex 2cb3df9678..d5710ca372 100644--- a/packages/playwright-core/src/server/chromium/crPage.ts+++ b/packages/playwright-core/src/server/chromium/crPage.ts@@ -439,7 +439,7 @@ class FrameSession {let videoOptions: types.VideoOptions | undefined;if (!this._page.isStorageStatePage && this._isMainFrame() && hasUIWindow)- videoOptions = this._crPage._page.screencast.launchVideoRecorder();+ videoOptions = this._crPage._page.screencast.launchAutomaticVideoRecorder();let lifecycleEventsEnabled: Promise<any>;if (!this._isMainFrame())diff --git a/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts b/packages/playwright-core/src/server/dispatchers/pageDispatcher.tsindex 22f65daf00..2979fb061b 100644--- a/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts@@ -337,6 +337,14 @@ export class PageDispatcher extends Dispatcher<Page, channels.PageChannel, Browsawait progress.race(this._page.bringToFront());}+ async videoStart(params: channels.PageVideoStartParams, progress: Progress): Promise<void> {+ await this._page.screencast.startExplicitVideoRecording(params);+ }++ async videoStop(params: channels.PageVideoStopParams, progress: Progress): Promise<channels.PageVideoStopResult> {+ await this._page.screencast.stopVideoRecording();+ }+async startJSCoverage(params: channels.PageStartJSCoverageParams, progress: Progress): Promise<void> {const coverage = this._page.coverage as CRCoverage;await coverage.startJSCoverage(progress, params);diff --git a/packages/playwright-core/src/server/firefox/ffPage.ts b/packages/playwright-core/src/server/firefox/ffPage.tsindex c6f478016c..d7e72b6af5 100644--- a/packages/playwright-core/src/server/firefox/ffPage.ts+++ b/packages/playwright-core/src/server/firefox/ffPage.ts@@ -99,7 +99,7 @@ export class FFPage implements PageDelegate {];const screencast = this._page.screencast;- const videoOptions = screencast.launchVideoRecorder();+ const videoOptions = screencast.launchAutomaticVideoRecorder();if (videoOptions)screencast.startVideoRecording(videoOptions).catch(e => debugLogger.log('error', e));diff --git a/packages/playwright-core/src/server/screencast.ts b/packages/playwright-core/src/server/screencast.tsindex 678056f7a0..b8c1a803bf 100644--- a/packages/playwright-core/src/server/screencast.ts+++ b/packages/playwright-core/src/server/screencast.ts@@ -20,6 +20,7 @@ import { debugLogger } from '../utils';import { VideoRecorder } from './videoRecorder';import { Page } from './page';import { registry } from './registry';+import { validateVideoSize } from './browserContext';import type * as types from './types';@@ -56,20 +57,24 @@ export class Screencast {this._frameThrottler.recharge();}- launchVideoRecorder(): types.VideoOptions | undefined {+ // Note: it is important to start video recorder before sending Screencast.startScreencast,+ // and it is equally important to send Screencast.startScreencast before sending Target.resume.+ launchAutomaticVideoRecorder(): types.VideoOptions | undefined {const recordVideo = this._page.browserContext._options.recordVideo;if (!recordVideo)- return undefined;+ return;+ // validateBrowserContextOptions ensures correct video size.+ return this._launchVideoRecorder(recordVideo.dir, recordVideo.size!);+ }++ private _launchVideoRecorder(dir: string, size: { width: number, height: number }): types.VideoOptions {assert(!this._videoId);this._videoId = createGuid();- const outputFile = path.join(recordVideo.dir, this._videoId + '.webm');+ const outputFile = path.join(dir, this._videoId + '.webm');const videoOptions = {- // validateBrowserContextOptions ensures correct video size.- ...recordVideo.size!,+ ...size,outputFile,};- // Note: it is important to start video recorder before sending Screencast.startScreencast,- // and it is equally important to send Screencast.startScreencast before sending Target.resume.const ffmpegPath = registry.findExecutable('ffmpeg')!.executablePathOrDie(this._page.browserContext._browser.sdkLanguage());this._videoRecorder = new VideoRecorder(ffmpegPath, videoOptions);this._frameListener = eventsHelper.addEventListener(this._page, Page.Events.ScreencastFrame, frame => this._videoRecorder!.writeFrame(frame.buffer, frame.frameSwapWallTime / 1000));@@ -114,6 +119,14 @@ export class Screencast {video?.reportFinished();}+ async startExplicitVideoRecording(options: { size?: types.Size } = {}) {+ if (this._videoId)+ throw new Error('Video is already being recorded');+ const size = validateVideoSize(options.size, this._page.emulatedSize()?.viewport);+ const videoOptions = this._launchVideoRecorder(this._page.browserContext._browser.options.artifactsDir, size);+ await this.startVideoRecording(videoOptions);+ }+private async _setOptions(options: { width: number, height: number, quality: number } | null): Promise<void> {if (options)await this._startScreencast(this, options);diff --git a/packages/playwright-core/src/server/webkit/wkPage.ts b/packages/playwright-core/src/server/webkit/wkPage.tsindex 0bdb92c031..c878690534 100644--- a/packages/playwright-core/src/server/webkit/wkPage.ts+++ b/packages/playwright-core/src/server/webkit/wkPage.ts@@ -846,7 +846,7 @@ export class WKPage implements PageDelegate {private async _initializeVideoRecording() {const screencast = this._page.screencast;- const videoOptions = screencast.launchVideoRecorder();+ const videoOptions = screencast.launchAutomaticVideoRecorder();if (videoOptions)await screencast.startVideoRecording(videoOptions);}diff --git a/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts b/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.tsindex 4da75fa607..e5a0f93715 100644--- a/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts+++ b/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts@@ -139,6 +139,8 @@ export const methodMetainfo = new Map<string, { internal?: boolean, title?: stri['Page.startCSSCoverage', { title: 'Start CSS coverage', group: 'configuration', }],['Page.stopCSSCoverage', { title: 'Stop CSS coverage', group: 'configuration', }],['Page.bringToFront', { title: 'Bring to front', }],+ ['Page.videoStart', { title: 'Start video recording', group: 'configuration', }],+ ['Page.videoStop', { title: 'Stop video recording', group: 'configuration', }],['Page.updateSubscription', { internal: true, }],['Page.agent', { internal: true, }],['Frame.evalOnSelector', { title: 'Evaluate', snapshot: true, pausesBeforeAction: true, }],diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.tsindex 50dd490708..ba9b01d9da 100644--- a/packages/playwright-core/types/types.d.ts+++ b/packages/playwright-core/types/types.d.ts@@ -4802,9 +4802,12 @@ export interface Page {url(): string;/**- * Video object associated with this page.+ * Video object associated with this page. Can be used to control video recording with+ * [video.start([options])](https://playwright.dev/docs/api/class-video#video-start) and+ * [video.stop([options])](https://playwright.dev/docs/api/class-video#video-stop), or to access the video file when+ * using the `recordVideo` context option.*/- video(): null|Video;+ video(): Video;viewportSize(): null|{/**@@ -21757,6 +21760,16 @@ export interface Tracing {* console.log(await page.video().path());* ```*+ * Alternatively, you can use [video.start([options])](https://playwright.dev/docs/api/class-video#video-start) and+ * [video.stop([options])](https://playwright.dev/docs/api/class-video#video-stop) to record video manually. This+ * approach is mutually exclusive with the `recordVideo` option.+ *+ * ```js+ * await page.video().start();+ * // ... perform actions ...+ * await page.video().stop({ path: 'video.webm' });+ * ```+ **/export interface Video {/**@@ -21776,6 +21789,50 @@ export interface Video {* @param path Path where the video should be saved.*/saveAs(path: string): Promise<void>;++ /**+ * Starts video recording. This method is mutually exclusive with the `recordVideo` context option.+ *+ * **Usage**+ *+ * ```js+ * await page.video().start();+ * // ... perform actions ...+ * await page.video().stop({ path: 'video.webm' });+ * ```+ *+ * @param options+ */+ start(options?: {+ /**+ * Optional dimensions of the recorded video. If not specified the size will be equal to page viewport scaled down to+ * fit into 800x800. Actual picture of the page will be scaled down if necessary to fit the specified size.+ */+ size?: {+ /**+ * Video frame width.+ */+ width: number;++ /**+ * Video frame height.+ */+ height: number;+ };+ }): Promise<void>;++ /**+ * Stops video recording started with+ * [video.start([options])](https://playwright.dev/docs/api/class-video#video-start) and either saves or discards the+ * video file.+ * @param options+ */+ stop(options?: {+ /**+ * Path where the video should be saved.+ */+ path?: string;+ }): Promise<void>;}/**diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.tsindex 874ba50ef2..f430dafdc5 100644--- a/packages/playwright/src/index.ts+++ b/packages/playwright/src/index.ts@@ -389,7 +389,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({const preserveVideo = captureVideo && (videoMode === 'on' || (testFailed && videoMode === 'retain-on-failure') || (videoMode === 'on-first-retry' && testInfo.retry === 1));if (preserveVideo) {const { pagesWithVideo: pagesForVideo } = contexts.get(context)!;- const videos = pagesForVideo.map(p => p.video()).filter(video => !!video);+ const videos = pagesForVideo.map(p => p.video());await Promise.all(videos.map(async v => {try {const savedPath = testInfo.outputPath(`video${counter ? '-' + counter : ''}.webm`);diff --git a/packages/protocol/src/channels.d.ts b/packages/protocol/src/channels.d.tsindex 86c22a6775..d0d42a9fd2 100644--- a/packages/protocol/src/channels.d.ts+++ b/packages/protocol/src/channels.d.ts@@ -2077,6 +2077,8 @@ export interface PageChannel extends PageEventTarget, EventTargetChannel {startCSSCoverage(params: PageStartCSSCoverageParams, progress?: Progress): Promise<PageStartCSSCoverageResult>;stopCSSCoverage(params?: PageStopCSSCoverageParams, progress?: Progress): Promise<PageStopCSSCoverageResult>;bringToFront(params?: PageBringToFrontParams, progress?: Progress): Promise<PageBringToFrontResult>;+ videoStart(params: PageVideoStartParams, progress?: Progress): Promise<PageVideoStartResult>;+ videoStop(params?: PageVideoStopParams, progress?: Progress): Promise<PageVideoStopResult>;updateSubscription(params: PageUpdateSubscriptionParams, progress?: Progress): Promise<PageUpdateSubscriptionResult>;agent(params: PageAgentParams, progress?: Progress): Promise<PageAgentResult>;}@@ -2574,6 +2576,22 @@ export type PageStopCSSCoverageResult = {export type PageBringToFrontParams = {};export type PageBringToFrontOptions = {};export type PageBringToFrontResult = void;+export type PageVideoStartParams = {+ size?: {+ width: number,+ height: number,+ },+};+export type PageVideoStartOptions = {+ size?: {+ width: number,+ height: number,+ },+};+export type PageVideoStartResult = void;+export type PageVideoStopParams = {};+export type PageVideoStopOptions = {};+export type PageVideoStopResult = void;export type PageUpdateSubscriptionParams = {event: 'console' | 'dialog' | 'fileChooser' | 'request' | 'response' | 'requestFinished' | 'requestFailed',enabled: boolean,diff --git a/packages/protocol/src/protocol.yml b/packages/protocol/src/protocol.ymlindex 9a66cd1bee..5b7b4ba293 100644--- a/packages/protocol/src/protocol.yml+++ b/packages/protocol/src/protocol.yml@@ -1998,6 +1998,20 @@ Page:bringToFront:title: Bring to front+ videoStart:+ title: Start video recording+ group: configuration+ parameters:+ size:+ type: object?+ properties:+ width: int+ height: int++ videoStop:+ title: Stop video recording+ group: configuration+updateSubscription:internal: trueparameters:diff --git a/tests/library/video.spec.ts b/tests/library/video.spec.tsindex 49b48459eb..4c87d78c5e 100644--- a/tests/library/video.spec.ts+++ b/tests/library/video.spec.ts@@ -132,6 +132,10 @@ function findVideos(videoDir: string) {}function expectRedFrames(videoFile: string, size: { width: number, height: number }) {+ expectFrames(videoFile, size, isAlmostRed);+}++function expectFrames(videoFile: string, size: { width: number, height: number }, pixelPredicate: PixelPredicate) {const videoPlayer = new VideoPlayer(videoFile);const duration = videoPlayer.duration;expect(duration).toBeGreaterThan(0);@@ -141,11 +145,11 @@ function expectRedFrames(videoFile: string, size: { width: number, height: numbe{const pixels = videoPlayer.seekLastFrame().data;- expectAll(pixels, isAlmostRed);+ expectAll(pixels, pixelPredicate);}{const pixels = videoPlayer.seekLastFrame({ x: size.width - 20, y: 0 }).data;- expectAll(pixels, isAlmostRed);+ expectAll(pixels, pixelPredicate);}}@@ -832,6 +836,63 @@ it.describe('screencast', () => {};expect(isAlmostRed(pixel)).toBe(true);});++ it('video.start/stop twice', async ({ browser, browserName }, testInfo) => {+ const size = browserName === 'firefox' ? { width: 500, height: 400 } : { width: 320, height: 240 };+ const context = await browser.newContext({ viewport: size });+ const page = await context.newPage();++ await page.video().start({ size });+ await page.evaluate(() => document.body.style.backgroundColor = 'red');+ await rafraf(page, 100);+ const videoPath1 = testInfo.outputPath('video1.webm');+ await page.video().stop({ path: videoPath1 });+ expectRedFrames(videoPath1, size);++ await page.video().start({ size });+ await page.evaluate(() => document.body.style.backgroundColor = 'rgb(100,100,100)');+ await rafraf(page, 100);+ const videoPath2 = testInfo.outputPath('video2.webm');+ await page.video().stop({ path: videoPath2 });+ expectFrames(videoPath2, size, isAlmostGray);++ const videoPath3 = testInfo.outputPath('video3.webm');+ await page.video().saveAs(videoPath3);+ const contents2 = fs.readFileSync(videoPath2).toString('base64');+ const contents3 = fs.readFileSync(videoPath3).toString('base64');+ expect(contents2 === contents3).toBeTruthy();++ await context.close();+ });++ it('should fail when recordVideo is set', async ({ browser }, testInfo) => {+ const size = { width: 320, height: 240 };+ const context = await browser.newContext({+ recordVideo: {+ dir: testInfo.outputPath(''),+ size+ },+ viewport: size,+ });+ const page = await context.newPage();++ const error = await page.video().start().catch(e => e);+ expect(error.message).toContain('Video is already being recorded');+ await context.close();+ });++ it('should fail when another recording is in progress', async ({ browser }, testInfo) => {+ const size = { width: 320, height: 240 };+ const context = await browser.newContext({+ viewport: size,+ });+ const page = await context.newPage();++ await page.video().start({ size });+ const error = await page.video().start().catch(e => e);+ expect(error.message).toContain('Video is already being recorded');+ await context.close();+ });});it('should saveAs video', async ({ browser }, testInfo) => {