Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(video): set default size to fit into 800x800 #5333

Merged
merged 4 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/server/browserContext.ts
Original file line number Diff line number Diff line change
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
32 changes: 25 additions & 7 deletions test/screencast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,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 +413,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 +430,26 @@ 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', 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