Skip to content

Commit 606733a

Browse files
authored
fix(playwright): set the record video resolution (#4311)
1 parent 4883feb commit 606733a

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/helper/Playwright.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,14 @@ class Playwright extends Helper {
417417
}
418418

419419
if (this.options.video) {
420-
this.options.recordVideo = { size: parseWindowSize(this.options.windowSize) };
420+
// set the video resolution with window size
421+
let size = parseWindowSize(this.options.windowSize);
422+
423+
// if the video resolution is passed, set the record resoultion with that resolution
424+
if (this.options.recordVideo && this.options.recordVideo.size) {
425+
size = parseWindowSize(this.options.recordVideo.size);
426+
}
427+
this.options.recordVideo = { size };
421428
}
422429
if (this.options.recordVideo && !this.options.recordVideo.dir) {
423430
this.options.recordVideo.dir = `${global.output_dir}/videos/`;
@@ -3656,6 +3663,11 @@ async function targetCreatedHandler(page) {
36563663

36573664
function parseWindowSize(windowSize) {
36583665
if (!windowSize) return { width: 800, height: 600 };
3666+
3667+
if (windowSize.width && windowSize.height) {
3668+
return { width: parseInt(windowSize.width, 10), height: parseInt(windowSize.height, 10) };
3669+
}
3670+
36593671
const dimensions = windowSize.split('x');
36603672
if (dimensions.length < 2 || windowSize === 'maximize') {
36613673
console.log('Invalid window size, setting window to default values');

test/helper/Playwright_test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,8 +1321,6 @@ describe('Playwright - Performance Metrics', () => {
13211321
show: false,
13221322
restart: true,
13231323
browser: 'chromium',
1324-
trace: true,
1325-
video: true,
13261324
});
13271325
I._init();
13281326
return I._beforeSuite();
@@ -1332,7 +1330,6 @@ describe('Playwright - Performance Metrics', () => {
13321330
webApiTests.init({
13331331
I, siteUrl,
13341332
});
1335-
deleteDir(path.join(global.output_dir, 'video'));
13361333
return I._before().then(() => {
13371334
page = I.page;
13381335
browser = I.browser;
@@ -1346,7 +1343,6 @@ describe('Playwright - Performance Metrics', () => {
13461343
it('grabs performance metrics', async () => {
13471344
await I.amOnPage('https://codecept.io');
13481345
const metrics = await I.grabMetrics();
1349-
console.log(metrics);
13501346
expect(metrics.length).to.greaterThan(0);
13511347
expect(metrics[0].name).to.equal('Timestamp');
13521348
});
@@ -1361,12 +1357,18 @@ describe('Playwright - Video & Trace & HAR', () => {
13611357

13621358
I = new Playwright({
13631359
url: siteUrl,
1364-
windowSize: '500x700',
1360+
windowSize: '300x500',
13651361
show: false,
13661362
restart: true,
13671363
browser: 'chromium',
13681364
trace: true,
13691365
video: true,
1366+
recordVideo: {
1367+
size: {
1368+
width: 400,
1369+
height: 600,
1370+
},
1371+
},
13701372
recordHar: {},
13711373
});
13721374
I._init();

0 commit comments

Comments
 (0)