To enable automatic video recording for failed tests and save the recordings in a specific folder using Playwright Python, you can use the recordVideo
option. This option allows you to record videos for all pages into a specified directory.
Here's a TypeScript example demonstrating how to set up video recording and launch a persistent context:
import { chromium } from 'playwright';
async function run() {
const browser = await chromium.launch();
const context = await browser.newContext({
recordVideo: {
dir: '/path/to/your/folder'
}
});
// Launching a persistent context with options
const persistentContext = await browserType.launchPersistentContext('/path/to/your/folder', {
recordVideo: {
dir: '/path/to/your/folder'
}
});
// Do some actions here
// Closing context after recording is complete
await persistentContext.close();
}
run();
In this example, we create a new context with the recordVideo
option using browser.newContext()
. Then, we launch a persistent context with the same option using browserType.launchPersistentContext()
. After performing some actions within our script, we close the persistent context by calling .close()
on it.
By implementing these steps in your Playwright Python script, you'll be able to enable automatic video recording for failed tests and save the recordings in a specific folder.
If you still have questions, please ask a question and I will try to answer it.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].