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

GitHub Actions运行Cypress失败:dri3报错及cy.visit()超时求助

问题解决方法

一、搞定GPU报错(dri3 extension not supported)

这个是Ubuntu环境下Chrome的GPU加速引发的问题,跑Cypress时加个禁用GPU的参数就能解决:

  • 修改Cypress运行命令,追加--browser chrome --args --disable-gpu;也可以直接在cypress.config.js里配置浏览器启动参数。

二、解决cy.visit()超时(ETIMEDOUT)的问题

1. 确认服务可被GitHub Runner访问

你用的https://192.168.11.96:9999/Edge是内网IP,GitHub的云Runner根本无法访问你的本地/内网机器。如果deploy_edge_service部署在云服务器上,得做这两点:

  • 给服务绑定公网IP或域名,同时开放9999端口的访问权限
  • 确保测试步骤执行时,服务已经完全启动(可以加个等待服务就绪的步骤)

2. 修复Node安装步骤的语法错误

你的setup-node步骤参数写错了,node:version应该是node-version,这会导致Node版本不符合要求,甚至影响依赖安装:

- name: Install node
  uses: actions/setup-node@v3
  with:
      node-version: '16' # 修正参数名

3. 简化依赖安装流程

npm ci会自动安装package.json里声明的所有依赖,没必要单独执行npm i -D cypress这类命令(除非你没把这些依赖写到package.json里)。建议把所有需要的依赖添加到package.json后,只保留npm ci:

- name: Install dependencies
  working-directory: ./integration_test/NetProbe_E2E/cypress
  run: npm ci

4. 确保IP正确传递到测试用例

检查你的测试代码:如果是硬编码了192.168.11.96,改成用环境变量传递更可靠。在GitHub Actions里设置环境变量:

- name: Cypress run
  working-directory: ./integration_test/NetProbe_E2E/cypress
  env:
    BASE_URL: "https://你的公网IP或域名:9999/Edge"
  run: npx cypress run --env grepTags="@trap @probe" --browser chrome --args --disable-gpu

然后在cypress.config.js里配置baseUrl:

module.exports = defineConfig({
  e2e: {
    baseUrl: process.env.BASE_URL,
  },
});

测试用例里用cy.visit('/')代替硬编码的完整地址,就能确保IP/域名通过环境变量正确传递了。

5. 添加服务健康检查步骤

跑Cypress之前,先等服务完全启动,比如用curl循环检查:

- name: Wait for service to be ready
  run: |
    until curl -s --head --request GET "$BASE_URL" | grep "200 OK"; do
      echo "Waiting for service..."
      sleep 5
    done
  env:
    BASE_URL: "https://你的公网IP或域名:9999/Edge"

三、修正后的完整GitHub Actions配置示例

integration_testing_portal_edge:
    name: Testing EDGE Portal
    runs-on: ubuntu-20.04
    needs: [deploy_edge_service]
    steps:
      - name: Checkout 
        uses: actions/checkout@v3
      - name: Install node
        uses: actions/setup-node@v3
        with:
            node-version: '16' # 修正参数名
            
      - name: Install dependencies
        working-directory: ./integration_test/NetProbe_E2E/cypress
        run: npm ci 
      
      - name: Wait for service to be ready
        run: |
          until curl -s --head --request GET "$BASE_URL" | grep "200 OK"; do
            echo "Waiting for service..."
            sleep 5
          done
        env:
          BASE_URL: "https://你的公网IP或域名:9999/Edge" # 替换为实际可访问的地址

      - name: Cypress run
        working-directory: ./integration_test/NetProbe_E2E/cypress
        env:
          BASE_URL: "https://你的公网IP或域名:9999/Edge" # 替换为实际可访问的地址
        run: npx cypress run --env grepTags="@trap @probe" --browser chrome --args --disable-gpu

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 16:50:27