Skip to content

Instantly share code, notes, and snippets.

@aslushnikov
Created September 8, 2020 23:13
Show Gist options
  • Save aslushnikov/614e69101c3dcc93d417ae13fd12a721 to your computer and use it in GitHub Desktop.
Save aslushnikov/614e69101c3dcc93d417ae13fd12a721 to your computer and use it in GitHub Desktop.
const playwright = require('.');
const path = require('path');
const fs = require('fs');
(async () => {
const browser = await playwright.chromium.launch({
_videosPath: __dirname,
});
const context = await browser.newContext({
_recordVideos: {width: 320, height: 240},
});
const [video] = await Promise.all([
new Promise(r => context.on('page', page => page.on('_videostarted', r))),
context.newPage(),
]);
/*
// The following doesn't work so we had to do ugly promise all above ^^
const page = await context.newPage();
const video = await page.waitForEvent('_videostarted');
*/
// Record a bit of screencast.
await new Promise(x => setTimeout(x, 1000));
const [videoFile] = await Promise.all([
video.path(),
context.close(),
]);
await browser.close();
if (!fs.existsSync(videoFile)) {
console.log('ERROR: Screencast is missing!');
process.exit(1);
}
console.log('SUCCESS: screencast at ' + videoFile);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment