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

Maven项目AWS CodePipeline中TestCafe启动chrome:headless失败求助

解决AWS CodePipeline中TestCafe启动headless Chrome报错"No inspectable targets"的问题

针对你遇到的TestCafe在AWS CodePipeline集成测试阶段无法启动chrome:headless、报错Error: No inspectable targets的问题,可尝试以下排查和解决步骤:

1. 添加Chrome headless模式的兼容启动参数

AWS CodeBuild的容器环境下,Chrome headless模式需要额外参数才能正常运行,修改TestCafe执行命令:

testcafe chrome:headless --no-sandbox --disable-gpu --disable-dev-shm-usage
  • --no-sandbox:绕过Chrome的沙箱机制,解决容器环境下的权限限制
  • --disable-dev-shm-usage:避免使用容器内有限的共享内存,防止Chrome启动失败
  • --disable-gpu:在无GPU的CI环境中禁用GPU加速,避免启动异常

2. 升级TestCafe到最新稳定版

旧版本TestCafe可能与CodeBuild环境中自动更新的Chrome版本存在兼容性问题,执行升级命令:

npm install testcafe@latest --save-dev

3. 检查CodeBuild资源配置

从日志总耗时3分钟来看,可能是环境资源不足导致Chrome启动超时。进入AWS CodeBuild控制台,将项目的构建环境资源规格从默认的small调整为medium或large,提升CPU和内存配额。

4. 确保应用服务完全启动后再执行测试

测试命令中的baseUrl指向http://localhost:18888,需保证应用服务在TestCafe执行前已完全就绪。可借助wait-on工具添加等待逻辑:

  1. 安装依赖:
npm install wait-on --save-dev
  1. 修改npm脚本:
"test-shop-chrome": "wait-on http://localhost:18888 && testcafe chrome:headless --no-sandbox --disable-gpu --disable-dev-shm-usage"

5. 调整frontend-maven-plugin的超时配置

延长插件执行npm命令的超时时间,避免因服务启动或测试初始化耗时过长导致失败,修改插件配置:

<plugin>
    <groupId>com.github.eirslett</groupId>
    <artifactId>frontend-maven-plugin</artifactId>
    <version>1.15.0</version>
    <executions>
        <execution>
            <id>e2e-npm-test</id>
            <goals>
                <goal>npm</goal>
            </goals>
            <configuration>
                <arguments>run test-shop-chrome</arguments>
                <timeout>360000</timeout> <!-- 设置为6分钟超时 -->
                <environmentVariables>
                    <NODE_ENV>test</NODE_ENV>
                </environmentVariables>
            </configuration>
        </execution>
    </executions>
</plugin>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 18:07:49