This thread is trying to answer question "How to configure recording option in cucumber.js file?"
This is the cucumber.conf.js file I have: Video gets recorded gets saved with scenario outline name: const { Before, BeforeAll, After, AfterAll, setDefaultTimeout, Status } = require("@cucumber/cucumber") const { chromium, firefox, webkit } = require('playwright') const fs = require('fs') const { globalAgent } = require("http")
require('dotenv').config() let setBrowser = process.env.setBrowser setDefaultTimeout(60000)
BeforeAll(async () => { switch (process.env.BROWSER) { case "firefox": console.log('Firefox is being launched') global.browser = await firefox.launch({ headless: true, slowMo: 1000, }) break case "chrome": console.log('Chrome is being launched') global.browser = await chromium.launch({ headless: false, slowMo: 1000, }) break default: console.log('Chrome is launched as default') global.browser = await chromium.launch({ headless: false, slowMo: 1000, }) } })
AfterAll(async () => { await global.browser.close() })
Before(async (scenario) => { global.context = await global.browser.newContext({ recordVideo: { dir: 'video/', }, }) global.page = await global.context.newPage() global.newWindow = global.page })
After(async (scenario) => {
if (scenario.result.status === Status.FAILED) {
await page.screenshot({
path: ./report/screenshots/${scenario.pickle.name}.png
,
fullpage: true,
}), "image/png"
}
await page.waitForTimeout(3000)
const videoName = await page.video().path()
fs.rename(videoName, './video/' + scenario.pickle.name + '.webm',
async () => await console.log('File is renamed as ' + scenario.pickle.name + '.webm'))
await global.page.close()
await global.context.close()
})
I'm using Javascript & Cucumber and Video is capturing now but It's not reading current scenario name. TypeError: Cannot read properties of undefined (reading 'pickle') error message is displayed `Before(async function ({this:World, scenario}) {
this.browser = await playwright.chromium.launch({
headless: false,
args:['--start-maximized']
});
//maximized & Record Video
this.context = await this.browser.newContext({
viewport: null,
recordVideo: {dir: 'video/'}
});
this.page = await this.context.newPage();
this.poManager = new POManager(this.browser, this.context, this.page);
this.scenarioName = scenario.pickle.name;
});`
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].