Skip to content

Commit

Permalink
fix(video): set default size to fit into 800x800 (#5333)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Feb 8, 2021
1 parent 7e757cd commit bb0af31
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/server/browserContext.ts
Expand Up @@ -414,6 +414,20 @@ export function validateBrowserContextOptions(options: types.BrowserContextOptio
throw new Error(`"isMobile" option is not supported with null "viewport"`);
if (!options.viewport && !options.noDefaultViewport)
options.viewport = { width: 1280, height: 720 };
if (options.recordVideo && !options.recordVideo.size) {
if (options.noDefaultViewport) {
options.recordVideo.size = { width: 800, height: 600 };
} else {
const size = options.viewport!;
const scale = 800 / Math.max(size.width, size.height);
if (scale < 1) {
options.recordVideo.size = {
width: Math.floor(size.width * scale),
height: Math.floor(size.height * scale)
};
}
}
}
if (options.proxy) {
if (!browserOptions.proxy)
throw new Error(`Browser needs to be launched with the global proxy. If all contexts override the proxy, global proxy will be never used and can be any string, for example "launch({ proxy: { server: 'per-context' } })"`);
Expand Down
36 changes: 29 additions & 7 deletions test/screencast.spec.ts
Expand Up @@ -45,6 +45,8 @@ export class VideoPlayer {

const lines = this.output.split('\n');
let framesLine = lines.find(l => l.startsWith('frame='))!;
if (!framesLine)
throw new Error(`No frame data in the output:\n${this.output}`);
framesLine = framesLine.substring(framesLine.lastIndexOf('frame='));
const framesMatch = framesLine.match(/frame=\s+(\d+)/);
const streamLine = lines.find(l => l.trim().startsWith('Stream #0:0'));
Expand Down Expand Up @@ -398,8 +400,8 @@ describe('screencast', suite => {
}
});

it('should use viewport as default size', async ({browser, testInfo}) => {
const size = {width: 800, height: 600};
it('should use viewport scaled down to fit into 800x800 as default size', async ({browser, testInfo}) => {
const size = {width: 1600, height: 1200};
const context = await browser.newContext({
recordVideo: {
dir: testInfo.outputPath(''),
Expand All @@ -413,11 +415,11 @@ describe('screencast', suite => {

const videoFile = await page.video().path();
const videoPlayer = new VideoPlayer(videoFile);
expect(videoPlayer.videoWidth).toBe(size.width);
expect(videoPlayer.videoHeight).toBe(size.height);
expect(videoPlayer.videoWidth).toBe(800);
expect(videoPlayer.videoHeight).toBe(600);
});

it('should be 1280x720 by default', async ({browser, testInfo}) => {
it('should be 800x450 by default', async ({browser, testInfo}) => {
const context = await browser.newContext({
recordVideo: {
dir: testInfo.outputPath(''),
Expand All @@ -430,8 +432,28 @@ describe('screencast', suite => {

const videoFile = await page.video().path();
const videoPlayer = new VideoPlayer(videoFile);
expect(videoPlayer.videoWidth).toBe(1280);
expect(videoPlayer.videoHeight).toBe(720);
expect(videoPlayer.videoWidth).toBe(800);
expect(videoPlayer.videoHeight).toBe(450);
});

it('should be 800x600 with null viewport', (test, { headful, browserName }) => {
test.fixme(browserName === 'firefox' && !headful, 'Fails in headless on bots');
}, async ({ browser, testInfo }) => {
const context = await browser.newContext({
recordVideo: {
dir: testInfo.outputPath(''),
},
viewport: null
});

const page = await context.newPage();
await new Promise(r => setTimeout(r, 1000));
await context.close();

const videoFile = await page.video().path();
const videoPlayer = new VideoPlayer(videoFile);
expect(videoPlayer.videoWidth).toBe(800);
expect(videoPlayer.videoHeight).toBe(600);
});

it('should capture static page in persistent context', async ({launchPersistent, testInfo}) => {
Expand Down

0 comments on commit bb0af31

Please sign in to comment.