You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions工作流yml报错Unexpected value 'with',请教添加browser: chrome方法

解决GitHub Actions中Cypress测试的with配置错误

错误原因

你碰到的报错是因为**run:步骤不支持with:配置项**,with:只能搭配uses:用来调用GitHub Action的步骤,直接用run:执行命令时加with:会导致工作流语法无效。

两种可行解决方案

方案1:改用Cypress官方Action运行测试(推荐)

把执行测试的步骤改成调用cypress-io/github-action,将浏览器参数和测试命令都放在with:里,符合Action的规范用法:

- name: Run Automation tests
  uses: cypress-io/github-action@v2
  with:
    browser: chrome
    command: npm run cy:run -- --env grepTags="@Envtest1",ENV="staging"

方案2:在npm命令中直接指定浏览器

如果想继续用run:执行命令,直接把浏览器参数加到命令行里即可:

- name: Run Automation tests
  run: npm run cy:run -- --browser chrome --env grepTags="@Envtest1",ENV="staging"

修正后的完整工作流示例

替换原文件中错误的测试步骤后,完整的tests jobs部分如下:

tests:
  runs-on: ubuntu-22.04
  needs: install
  steps:
    - name: Check out code
      uses: actions/checkout@v2
    # 重新安装依赖
    - name: Install dependencies
      uses: cypress-io/github-action@v2
      with:
        # 仅执行安装
        runTests: false

    # 这里替换成上面两种方案中的任意一种
    - name: Run Automation tests
      uses: cypress-io/github-action@v2
      with:
        browser: chrome
        command: npm run cy:run -- --env grepTags="@Envtest1",ENV="staging"
        
    - name: Upload Results
      uses: actions/upload-artifact@v3
      if: failure()
      with:
        name: cypress-screenshots
        path: cypress/screenshots
    - uses: actions/upload-artifact@v2
      if: always()
      with:
        name: cypress-videos
        path: cypress/videos

内容的提问来源于stack exchange,提问作者soccerway

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 17:25:19