@dnvgl/playwright-live-recorder

中文文档
2.0.72发布于 2025/08/14MITCommonJS近 30 天下载 3965

Adds live coding in testing context from browser console when running tests. Provides programmatically configurable recorder. Introduces the idea of strong convention for Page Object Model

原始使用文档
文档目录6 节
  1. Watch the video demonstration
  2. Prerequisites
  3. Install
  4. Typescript Code for test
  5. Browser
  6. Recording

Playwright live recorder infographic

Getting Started

Watch the video demonstration

Getting Started


Prerequisites

@playwright/test (typescript)

start with a repo with @playwright/test set up, if starting with a new repo see https://playwright.dev/docs/intro

Install

npm install -D @dnvgl/playwright-live-recorder
#or
yarn add -D @dnvgl/playwright-live-recorder
#or
pnpm add -D @dnvgl/playwright-live-recorder

run the setup script

npx @dnvgl/playwright-live-recorder

Ensure baseURL is set to the root url of your webapp in playwright.config.ts e.g.

//playwright.config.ts
export default defineConfig({
  //...
  use: {
    baseURL: 'https://demo.playwright.dev/todomvc/#/',
    //...

How to use

Typescript Code for test

In a playwright test, add the import

import { PlaywrightLiveRecorder } from '@dnvgl/playwright-live-recorder';

and then add this await line at the end of the playwright test you want to record into

// note - recorded lines will be inserted here
await PlaywrightLiveRecorder.start(page, s => <undefined>eval(s));

Run the test in headed mode

💡 if you're using the vscode plugin ms-playwright.playwright it will automatically run in headed mode with PWDEBUG set to console (see modifications to .vscode/settings.json)
💡 if you're running from the command line, set the environment variable PWDEBUG=console before running the playwright command, e.g. playwright test --ui

Test will run, when PlaywrightLiveRecorder.start line is executed lib functionality will be exposed to the browser and all scripts will be loaded in the browser. Test execution waits until browser is closed.
Newly recorded test lines are inserted into test file.
Newly added page object model files will be created, newly added items are inserted into the page object model files.
Newly added or modified test lines above PlaywrightLiveRecorder.start are executed upon file save.

Browser

Playwright live recorder sticky bar
Playwright live recorder adds a control bar to the top of the browser page.

  • Record mode ⚪/🔴 can be toggled off/on by clicking the icon, or pressing CTRL+ALT+SHIFT+R
  • The label is the page object model path+filename
  • the f(x) button displays public helper functions available from your page object model file, click the green ➕ to add an example to the file

When record is toggled on a hover tooltip is positioned next to the cursor showing the code that will be generated

💡 if the recorder blocks your testing session, work past it by toggling record off, clicking, then toggling it back on

Recording

With record toggled on, click an element to add it to your test

  • If the element is not part of the Page Object Model, you will be prompted to give it a name
    • Press enter and the new property will be added to the page object model file, and the element will highlight (default: salmon color), to indicate it's a part of the page object model
    • Press [esc] to skip adding to the page object model
  • If the element is part of the Page Object Model, it will already be highlighted salmon color
    • Clicking it will add a call to the page object model method to your test

After clicking an element, the test code will be added and saved to your test file. File changes are automatically re-executed.
You can always modify the text code and save to re-execute changed lines.

💡 This is useful to change a .click() call to a .fill(), or to wrap an expect around the element you just clicked. Save the file and it's re-executed. Another powerful workflow is to edit the page object model function, save the file, and then add the same line again to the test file to force a re-execute You can keep iterating this way until the function implementation is correct.

💡 whenever code lines are executed in the test they'll display overlayed on-screen code execute overlay

版本与发布记录

@dnvgl/playwright-live-recorder 共发布 63 个版本,首次发布于 2022/09/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.72latest2025/08/141.2 年前
2.0.712025/08/141.2 年前
2.0.682025/07/191.3 年前
2.0.672025/07/191.3 年前
2.0.662025/07/191.3 年前
2.0.652025/07/121.3 年前

关于 @dnvgl/playwright-live-recorder 的常见问题

@dnvgl/playwright-live-recorder 是什么?

Adds live coding in testing context from browser console when running tests. Provides programmatically configurable recorder. Introduces the idea of strong convention for Page Object Model

如何安装 @dnvgl/playwright-live-recorder?

在项目目录运行 npm install @dnvgl/playwright-live-recorder,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 playwright-live-recorder,可以用 npx playwright-live-recorder 直接运行。

@dnvgl/playwright-live-recorder 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dnvgl__playwright-live-recorder 是否存在。

@dnvgl/playwright-live-recorder 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dnvgl/playwright-live-recorder 可以商用吗?

@dnvgl/playwright-live-recorder 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dnvgl/playwright-live-recorder 的下载量有多少?

根据 npm 官方下载统计,@dnvgl/playwright-live-recorder 在 2026/10/13 – 2026/11/11 这 30 天内被下载 3,965 次,日均约 132 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dnvgl/playwright-live-recorder 还在维护吗?

最新版本 2.0.72 发布于 2025/08/14(1.2 年前);至今共发布 63 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/09/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。