@cypress/chrome-recorder

中文文档
2.3.1发布于 2023/04/20MITTypeScriptES Module近 30 天下载 5094

Generate Cypress Tests from Chrome DevTools Recordings

原始使用文档
文档目录8 节
  1. Prerequisites
  2. Installation
  3. Usage
  4. Via CLI
  5. CLI Options
  6. Via Import
  7. Supported Chrome Recorder Step Types
  8. License

@cypress/chrome-recorder

npm version Commitizen friendly

This repo provides tools to export Cypress Tests from Google Chrome DevTools' Recordings programmatically.

Install Cypress Chrome Recorder extension if you want to export the recordings directly from the Chrome DevTools' Recorder UI.

Cypress Chrome Recorder Demo

Prerequisites

In order to export JSON files from Chrome DevTools Recorder you will need to be on Chrome 101 or newer.

dblClick and rightclick require Chrome 103 or newer.

Installation

$ npm install -g @cypress/chrome-recorder

Usage

Via CLI

To use the interactive CLI, run:

$ npx @cypress/chrome-recorder

The CLI will prompt you to enter the path of the directory or file that you would like to modify as well as a path to write the generated Cypress test to.

If you prefer to enter paths via the CLI, you can run the following command to export individual recordings:

$ npx @cypress/chrome-recorder <relative path to target test file>

or for folders containing multiple recordings:

$ npx @cypress/chrome-recorder <relative path to target test folder>/*.json

By default the output will be written to cypress/integration with a fallback to cypress/e2e. If you do not have those folders, create them manually or install Cypress by running yarn add -D cypress or npm install --save-dev cypress in your project.

If you prefer a different output directory, specify that via CLI:

$ npx @cypress/chrome-recorder <relative path to target test folder>/*.json --output=folder-name

or via the interactive CLI prompts.

CLI Options

OptionDescription
-f, --forceBypass Git safety checks and force exporter to run
-d, --dryDry run (no changes are made to files)
-o, --outputOutput location of the files generated by the exporter
-p, --printPrint transformed files to stdout, useful for development

Via Import

import { cypressStringifyChromeRecording } from '@cypress/chrome-recorder';

const stringifiedContent = await cypressStringifyChromeRecording(
  recordingContent
);

return stringifiedContent;

Supported Chrome Recorder Step Types

Below are the step types that are currently supported:

TypeDescription
changebecomes cy.get("element").type("text")
clickbecomes cy.get("element").click();
click (right click)becomes cy.get("element").rightclick();
doubleClickbecomes cy.get("element").dblclick();
hoverbecomes cy.get("element").trigger();
keyDownbecomes cy.type("{key}")
keyUpnot exported at this time
navigatebecomes cy.visit("url")
setViewportbecomes cy.viewport(width, height)
scrollbecomes cy.scrollTo(${step.x}, ${step.y})

If a step type is not listed above, then a warning message should be displayed in the CLI.

License

license

This project is licensed under the terms of the MIT license.

版本与发布记录

@cypress/chrome-recorder 共发布 10 个版本,首次发布于 2022/04/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.3.1latest2023/04/203 年前
2.3.02022/11/173 年前
2.2.02022/08/224 年前
2.1.02022/08/184 年前
2.0.02022/07/194 年前
1.4.02022/05/144 年前

关于 @cypress/chrome-recorder 的常见问题

@cypress/chrome-recorder 是什么?

Generate Cypress Tests from Chrome DevTools Recordings

如何安装 @cypress/chrome-recorder?

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

@cypress/chrome-recorder 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cypress/chrome-recorder 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cypress/chrome-recorder 可以商用吗?

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

@cypress/chrome-recorder 的下载量有多少?

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

@cypress/chrome-recorder 还在维护吗?

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