Created
September 8, 2020 23:13
-
-
Save aslushnikov/614e69101c3dcc93d417ae13fd12a721 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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