fix(video): make video path available in persistent profiles (#4182)
This commit is contained in:
parent
bf491f12cf
commit
5d997ed28b
|
|
@ -237,6 +237,9 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
|
||||||
if (!this._browserContext._options.videosPath)
|
if (!this._browserContext._options.videosPath)
|
||||||
return null;
|
return null;
|
||||||
this._video = new Video(this);
|
this._video = new Video(this);
|
||||||
|
// In case of persistent profile, we already have it.
|
||||||
|
if (this._initializer.videoRelativePath)
|
||||||
|
this._video._setRelativePath(this._initializer.videoRelativePath);
|
||||||
return this._video;
|
return this._video;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ export class PageDispatcher extends Dispatcher<Page, channels.PageInitializer> i
|
||||||
// If we split pageCreated and pageReady, there should be no main frame during pageCreated.
|
// If we split pageCreated and pageReady, there should be no main frame during pageCreated.
|
||||||
super(scope, page, 'Page', {
|
super(scope, page, 'Page', {
|
||||||
mainFrame: FrameDispatcher.from(scope, page.mainFrame()),
|
mainFrame: FrameDispatcher.from(scope, page.mainFrame()),
|
||||||
|
videoRelativePath: page._video ? page._video._relativePath : undefined,
|
||||||
viewportSize: page.viewportSize() || undefined,
|
viewportSize: page.viewportSize() || undefined,
|
||||||
isClosed: page.isClosed()
|
isClosed: page.isClosed()
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -664,6 +664,7 @@ export type PageInitializer = {
|
||||||
height: number,
|
height: number,
|
||||||
},
|
},
|
||||||
isClosed: boolean,
|
isClosed: boolean,
|
||||||
|
videoRelativePath?: string,
|
||||||
};
|
};
|
||||||
export interface PageChannel extends Channel {
|
export interface PageChannel extends Channel {
|
||||||
on(event: 'bindingCall', callback: (params: PageBindingCallEvent) => void): this;
|
on(event: 'bindingCall', callback: (params: PageBindingCallEvent) => void): this;
|
||||||
|
|
|
||||||
|
|
@ -585,6 +585,7 @@ Page:
|
||||||
width: number
|
width: number
|
||||||
height: number
|
height: number
|
||||||
isClosed: boolean
|
isClosed: boolean
|
||||||
|
videoRelativePath: string?
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ export abstract class Browser extends EventEmitter {
|
||||||
context.emit(BrowserContext.Events.VideoStarted, video);
|
context.emit(BrowserContext.Events.VideoStarted, video);
|
||||||
pageOrError.then(pageOrError => {
|
pageOrError.then(pageOrError => {
|
||||||
if (pageOrError instanceof Page)
|
if (pageOrError instanceof Page)
|
||||||
pageOrError.emit(Page.Events.VideoStarted, video);
|
pageOrError.videoStarted(video);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import * as network from './network';
|
||||||
import { Screenshotter } from './screenshotter';
|
import { Screenshotter } from './screenshotter';
|
||||||
import { TimeoutSettings } from '../utils/timeoutSettings';
|
import { TimeoutSettings } from '../utils/timeoutSettings';
|
||||||
import * as types from './types';
|
import * as types from './types';
|
||||||
import { BrowserContext } from './browserContext';
|
import { BrowserContext, Video } from './browserContext';
|
||||||
import { ConsoleMessage } from './console';
|
import { ConsoleMessage } from './console';
|
||||||
import * as accessibility from './accessibility';
|
import * as accessibility from './accessibility';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
|
|
@ -143,6 +143,7 @@ export class Page extends EventEmitter {
|
||||||
private _requestInterceptor?: network.RouteHandler;
|
private _requestInterceptor?: network.RouteHandler;
|
||||||
_ownedContext: BrowserContext | undefined;
|
_ownedContext: BrowserContext | undefined;
|
||||||
readonly selectors: Selectors;
|
readonly selectors: Selectors;
|
||||||
|
_video: Video | null = null;
|
||||||
|
|
||||||
constructor(delegate: PageDelegate, browserContext: BrowserContext) {
|
constructor(delegate: PageDelegate, browserContext: BrowserContext) {
|
||||||
super();
|
super();
|
||||||
|
|
@ -416,6 +417,11 @@ export class Page extends EventEmitter {
|
||||||
async _setFileChooserIntercepted(enabled: boolean): Promise<void> {
|
async _setFileChooserIntercepted(enabled: boolean): Promise<void> {
|
||||||
await this._delegate.setFileChooserIntercepted(enabled);
|
await this._delegate.setFileChooserIntercepted(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
videoStarted(video: Video) {
|
||||||
|
this._video = video;
|
||||||
|
this.emit(Page.Events.VideoStarted, video);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Worker extends EventEmitter {
|
export class Worker extends EventEmitter {
|
||||||
|
|
|
||||||
|
|
@ -128,11 +128,6 @@ function expectAll(pixels: Buffer, rgbaPredicate) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function findVideo(videoDir: string) {
|
|
||||||
const files = fs.readdirSync(videoDir);
|
|
||||||
return path.join(videoDir, files.find(file => file.endsWith('webm')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function findVideos(videoDir: string) {
|
function findVideos(videoDir: string) {
|
||||||
const files = fs.readdirSync(videoDir);
|
const files = fs.readdirSync(videoDir);
|
||||||
return files.filter(file => file.endsWith('webm')).map(file => path.join(videoDir, file));
|
return files.filter(file => file.endsWith('webm')).map(file => path.join(videoDir, file));
|
||||||
|
|
@ -146,11 +141,9 @@ describe('screencast', suite => {
|
||||||
expect(error.message).toContain('"videoSize" option requires "videosPath" to be specified');
|
expect(error.message).toContain('"videoSize" option requires "videosPath" to be specified');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should capture static page', (test, { browserName }) => {
|
it('should capture static page', async ({browser, testInfo}) => {
|
||||||
test.fixme(browserName === 'firefox', 'Always clips to square');
|
|
||||||
}, async ({browser, testInfo}) => {
|
|
||||||
const videosPath = testInfo.outputPath('');
|
const videosPath = testInfo.outputPath('');
|
||||||
const size = { width: 320, height: 240 };
|
const size = { width: 450, height: 240 };
|
||||||
const context = await browser.newContext({
|
const context = await browser.newContext({
|
||||||
videosPath,
|
videosPath,
|
||||||
viewport: size,
|
viewport: size,
|
||||||
|
|
@ -162,12 +155,12 @@ describe('screencast', suite => {
|
||||||
await new Promise(r => setTimeout(r, 1000));
|
await new Promise(r => setTimeout(r, 1000));
|
||||||
await context.close();
|
await context.close();
|
||||||
|
|
||||||
const videoFile = findVideo(videosPath);
|
const videoFile = await page.video().path();
|
||||||
const videoPlayer = new VideoPlayer(videoFile);
|
const videoPlayer = new VideoPlayer(videoFile);
|
||||||
const duration = videoPlayer.duration;
|
const duration = videoPlayer.duration;
|
||||||
expect(duration).toBeGreaterThan(0);
|
expect(duration).toBeGreaterThan(0);
|
||||||
|
|
||||||
expect(videoPlayer.videoWidth).toBe(320);
|
expect(videoPlayer.videoWidth).toBe(450);
|
||||||
expect(videoPlayer.videoHeight).toBe(240);
|
expect(videoPlayer.videoHeight).toBe(240);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -175,7 +168,7 @@ describe('screencast', suite => {
|
||||||
expectAll(pixels, almostRed);
|
expectAll(pixels, almostRed);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const pixels = videoPlayer.seekLastFrame({ x: 300, y: 0}).data;
|
const pixels = videoPlayer.seekLastFrame({ x: 430, y: 0}).data;
|
||||||
expectAll(pixels, almostRed);
|
expectAll(pixels, almostRed);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -244,7 +237,7 @@ describe('screencast', suite => {
|
||||||
await new Promise(r => setTimeout(r, 1000));
|
await new Promise(r => setTimeout(r, 1000));
|
||||||
await context.close();
|
await context.close();
|
||||||
|
|
||||||
const videoFile = findVideo(videosPath);
|
const videoFile = await page.video().path();
|
||||||
const videoPlayer = new VideoPlayer(videoFile);
|
const videoPlayer = new VideoPlayer(videoFile);
|
||||||
const duration = videoPlayer.duration;
|
const duration = videoPlayer.duration;
|
||||||
expect(duration).toBeGreaterThan(0);
|
expect(duration).toBeGreaterThan(0);
|
||||||
|
|
@ -277,7 +270,7 @@ describe('screencast', suite => {
|
||||||
await new Promise(r => setTimeout(r, 1000));
|
await new Promise(r => setTimeout(r, 1000));
|
||||||
await context.close();
|
await context.close();
|
||||||
|
|
||||||
const videoFile = findVideo(videosPath);
|
const videoFile = await page.video().path();
|
||||||
const videoPlayer = new VideoPlayer(videoFile);
|
const videoPlayer = new VideoPlayer(videoFile);
|
||||||
const duration = videoPlayer.duration;
|
const duration = videoPlayer.duration;
|
||||||
expect(duration).toBeGreaterThan(0);
|
expect(duration).toBeGreaterThan(0);
|
||||||
|
|
@ -332,7 +325,7 @@ describe('screencast', suite => {
|
||||||
await new Promise(r => setTimeout(r, 1000));
|
await new Promise(r => setTimeout(r, 1000));
|
||||||
await context.close();
|
await context.close();
|
||||||
|
|
||||||
const videoFile = findVideo(videosPath);
|
const videoFile = await page.video().path();
|
||||||
const videoPlayer = new VideoPlayer(videoFile);
|
const videoPlayer = new VideoPlayer(videoFile);
|
||||||
const duration = videoPlayer.duration;
|
const duration = videoPlayer.duration;
|
||||||
expect(duration).toBeGreaterThan(0);
|
expect(duration).toBeGreaterThan(0);
|
||||||
|
|
@ -363,11 +356,11 @@ describe('screencast', suite => {
|
||||||
viewport: size,
|
viewport: size,
|
||||||
});
|
});
|
||||||
|
|
||||||
await context.newPage();
|
const page = await context.newPage();
|
||||||
await new Promise(r => setTimeout(r, 1000));
|
await new Promise(r => setTimeout(r, 1000));
|
||||||
await context.close();
|
await context.close();
|
||||||
|
|
||||||
const videoFile = findVideo(videosPath);
|
const videoFile = await page.video().path();
|
||||||
const videoPlayer = new VideoPlayer(videoFile);
|
const videoPlayer = new VideoPlayer(videoFile);
|
||||||
expect(await videoPlayer.videoWidth).toBe(size.width);
|
expect(await videoPlayer.videoWidth).toBe(size.width);
|
||||||
expect(await videoPlayer.videoHeight).toBe(size.height);
|
expect(await videoPlayer.videoHeight).toBe(size.height);
|
||||||
|
|
@ -379,11 +372,11 @@ describe('screencast', suite => {
|
||||||
videosPath,
|
videosPath,
|
||||||
});
|
});
|
||||||
|
|
||||||
await context.newPage();
|
const page = await context.newPage();
|
||||||
await new Promise(r => setTimeout(r, 1000));
|
await new Promise(r => setTimeout(r, 1000));
|
||||||
await context.close();
|
await context.close();
|
||||||
|
|
||||||
const videoFile = findVideo(videosPath);
|
const videoFile = await page.video().path();
|
||||||
const videoPlayer = new VideoPlayer(videoFile);
|
const videoPlayer = new VideoPlayer(videoFile);
|
||||||
expect(await videoPlayer.videoWidth).toBe(1280);
|
expect(await videoPlayer.videoWidth).toBe(1280);
|
||||||
expect(await videoPlayer.videoHeight).toBe(720);
|
expect(await videoPlayer.videoHeight).toBe(720);
|
||||||
|
|
@ -402,7 +395,7 @@ describe('screencast', suite => {
|
||||||
await new Promise(r => setTimeout(r, 1000));
|
await new Promise(r => setTimeout(r, 1000));
|
||||||
await context.close();
|
await context.close();
|
||||||
|
|
||||||
const videoFile = findVideo(videosPath);
|
const videoFile = await page.video().path();
|
||||||
const videoPlayer = new VideoPlayer(videoFile);
|
const videoPlayer = new VideoPlayer(videoFile);
|
||||||
const duration = videoPlayer.duration;
|
const duration = videoPlayer.duration;
|
||||||
expect(duration).toBeGreaterThan(0);
|
expect(duration).toBeGreaterThan(0);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue