Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 16, 2023 01:07 pm GMT

Playwright Tutorial For Beginners 7 - Videos

Playwright can record videos for all pages in a browser context.

A BrowserContext is an isolated incognito-alike session within a browser. Just like when you open an incognito window of your browser, the browser state (cache, cookies etc.) is isolated between test.

Using the page provide by Playwright test runner, @playwright/test, the page provided in the tests callback opens in a new context out of the box.

To record a video, we will:

  • create a new context from a browser with some options in place
  • create a new page with from the context
  • open a web app in the page
  • make sure to close the context (the video is generated after this

We will create a test scripts in demo.spec.js and run to generate a video:

// demo.spec.jsconst { test } = require('@playwright/test');test('Demo video', async ({ browser }) => {  const context = await browser.newContext({ recordVideo: { dir: 'videos' } });  const page = await context.newPage();  await page.goto('https://google.com');  await page.type('input', 'playwright');  await page.press('input', 'Enter');  await page.waitForTimeout(1000);  await context.close();});

The test will generate a video in a /videos folder.

generated video


Original Link: https://dev.to/zt4ff_1/playwright-tutorial-for-beginners-7-videos-591n

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To