Cypress GitHub Actions执行报错:cypress-ntlm-auth插件需提前加载
问题解决:CI中Cypress-ntlm-auth插件未加载报错
问题原因
你的CI流程存在两个核心问题:
- 未在CI环境中执行
npm install,导致cypress-ntlm-auth依赖未安装 - 使用Cypress官方GitHub Action的默认执行逻辑,没有通过
cypress-ntlm命令启动Cypress,插件无法被正确加载
修复方案
1. 调整CI流程步骤
修改你的YML文件,补充依赖安装步骤,并指定正确的Cypress启动命令:
name: (PUSH) Test123 on: push: branches: [ branchname] jobs: cypress-run: name: Cypress automation runs-on: runnerid if: "!contains(github.event.head_commit.message, 'skip ci')" steps: - name: 拉取代码 uses: actions/checkout@v3 - name: 配置Node.js环境 uses: actions/setup-node@v2 with: node-version: 16 # 替换为你本地使用的Node版本,避免版本差异 - name: 设置代理 run: | npm config set https-proxy http://domain.company.com:911 npm config set proxy http://domain.company.com:912 npm config set strict-ssl false - name: 安装项目依赖 working-directory: Cypress run: npm install - name: 执行Cypress自动化 uses: cypress-io/github-action@v5 with: working-directory: Cypress command: npx cypress-ntlm run
2. 确认插件注册正确
确保你的Cypress配置文件(Cypress 9对应cypress/plugins/index.js)已正确注册cypress-ntlm-auth插件:
const ntlmAuth = require('cypress-ntlm-auth/dist/plugin'); module.exports = (on, config) => { ntlmAuth.initNtlmAuth(config); return config; };
关键说明
本地能正常运行是因为你已手动完成依赖安装,并通过cypress-ntlm命令启动Cypress;但CI是全新环境,必须明确执行依赖安装步骤,且用cypress-ntlm命令替代默认的cypress run,才能确保插件被加载。
内容的提问来源于stack exchange,提问作者prahlad
相关产品推荐
相关产品推荐

