在剧作家中录制魅力的视频

发布于 2025-02-06 03:57:10 字数 248 浏览 4 评论 0 原文

如何录制视频,并将其附加到Trace或屏幕截图之类的魅力?

 use: {

    actionTimeout: 0,
    trace: 'on',
    screenshot: 'on',
    viewport: {width:1920, height: 1080},
    video: 'on',
  },

这就是我在playwright.config.ts和视频中所拥有的只是一个不起作用的东西。

How can I record a video and it will be attached to allure like trace or screenshot?

 use: {

    actionTimeout: 0,
    trace: 'on',
    screenshot: 'on',
    viewport: {width:1920, height: 1080},
    video: 'on',
  },

that's what I have in playwright.config.ts and video is only one what is NOT working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧话新听 2025-02-13 03:57:10

根据 dir recordVideo 上下文选项的属性。否则不会录制视频。因此,您的配置文件应该看起来像这样:

use = {
  actionTimeout: 0,
  trace: 'on',
  screenshot: 'on',
  viewport: { width: 1920, height: 1080 },
  video: 'on',
  contextOptions: {
    recordVideo: {
      dir: './output' // Or wherever you want the videos to be saved.
    }
  }
}

另外,您可以指定录制视频目录

不要忘记在测试结束时致电 browsercontext.close(),以成功保存视频。就个人而言,我在 test.afterall()挂钩中进行此操作。

edit :有一个 open oble Issue 关于某些配置选项无法按预期工作,包括视频一个。在第一个评论中,其中一位开发人员指出视频在这种情况下不起作用,这是一个已知的问题。。也许您可以完全跳过视频选项 - 我想它仍然可以正常工作。

edit2 :要将视频录制附加到Allure Reporter,请在 test.afterall() Hook中包含以下代码:

test.afterAll(async ({ }, testInfo) => {
  await context.close() // Required for successful save of video recording.
  const path = await page.video().path()
  await testInfo.attach('video', {
    path,
    contentType: 'video/webm',
  })
})

According to the documentation, you have to specify the dir property of recordVideo context option. Otherwise videos are not recorded. Thus, your configuration file should look like this:

use = {
  actionTimeout: 0,
  trace: 'on',
  screenshot: 'on',
  viewport: { width: 1920, height: 1080 },
  video: 'on',
  contextOptions: {
    recordVideo: {
      dir: './output' // Or wherever you want the videos to be saved.
    }
  }
}

Also, you can specify the record video directory on page level.

Don't forget to call browserContext.close() at the end of your tests, for the videos to be successfully saved. Personally, I do it in test.afterAll() hook.

EDIT: There is an open issue regarding some config options not working as expected, including the video one. On the first comment, one of the developers states that "Video does not work in this case, that's a known issue.". Maybe you can skip the video option completely - I guess it will still work.

EDIT2: To attach the video recording to Allure reporter, include the following code in test.afterAll() hook:

test.afterAll(async ({ }, testInfo) => {
  await context.close() // Required for successful save of video recording.
  const path = await page.video().path()
  await testInfo.attach('video', {
    path,
    contentType: 'video/webm',
  })
})
成熟稳重的好男人 2025-02-13 03:57:10

对于带有Allure报告视频的剧作家

After(async function (this: ICustomWorld, { result, pickle }: ITestCaseHookParameter) { 
   ...
   await this.page?.close();
   await this.context?.close();
   ...
   const buffer = fs.readFileSync(videoPath);
   await this.attach(buffer, 'video/webm'); 
});

,将显示为链接附件,单击它时 - 在下一个Tab Video中打开带有方案的标签视频

for playwright with allure report

After(async function (this: ICustomWorld, { result, pickle }: ITestCaseHookParameter) { 
   ...
   await this.page?.close();
   await this.context?.close();
   ...
   const buffer = fs.readFileSync(videoPath);
   await this.attach(buffer, 'video/webm'); 
});

video will be attached, it is shown as a link attachment, when click on it - open in the next tab video with scenario run
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文