Cypress 10版本中如何配置启用htmlvalidate插件?
Cypress 10+ 配置 cypress-html-validate 方法
在 Cypress 9 及以下版本中,我们通过 cypress/plugins/index.js 安装 cypress-html-validate:
const htmlvalidate = require("cypress-html-validate/dist/plugin"); module.exports = (on) => { htmlvalidate.install(on); };
升级到 Cypress 10+ 后,插件机制被弃用,需在 defineConfig 的 setupNodeEvents 中完成配置,具体步骤如下:
Node 端配置
修改你的 Cypress 配置文件(通常是cypress.config.js),在setupNodeEvents中直接调用htmlvalidate.install(on)即可,无需手动编写 task:const { defineConfig } = require('cypress'); const htmlvalidate = require("cypress-html-validate/dist/plugin"); module.exports = defineConfig({ projectId: '4dofbo', e2e: { setupNodeEvents(on, config) { htmlvalidate.install(on); }, }, });客户端命令注册
在 Cypress 支持文件(比如cypress/support/e2e.js)中导入cypress-html-validate的命令,这样就能在测试用例中使用cy.htmlvalidate():import "cypress-html-validate/dist/commands";
完成以上两步后,就可以正常在测试中执行 HTML 校验了。
内容的提问来源于stack exchange,提问作者alias51
相关产品推荐
相关产品推荐

