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

GitLab CI/CD流水线配置报错:'services config should be a array'

WebdriverIO TypeScript Cucumber GitLab CI/CD 配置修复

原配置的核心问题

  • 全局services定义不符合GitLab CI规范,正确做法是将Selenium相关服务配置在测试Job中,而非全局顶层
  • 使用huli/webdriverio镜像不合适:该镜像并非通用Node.js运行环境,无法正常执行npm install和TypeScript编译流程
  • 仅挂载wdio.conf.ts到容器,缺少整个项目代码、依赖文件的挂载,导致测试执行时找不到测试用例和依赖包
  • Build阶段的依赖未传递到Test阶段,重复执行npm install会浪费时间且可能导致版本不一致

修正后的.gitlab-ci.yml配置

stages:
  - install
  - test

# 缓存依赖,避免重复安装
cache:
  paths:
    - node_modules/
    - .npm/

install-deps:
  stage: install
  image: node:18-alpine  # 根据项目Node版本调整镜像
  script:
    - npm config set cache .npm
    - npm install --frozen-lockfile  # 用lockfile保证依赖版本一致

smoke-test:
  stage: test
  image: node:18-alpine
  services:
    - name: selenium/hub:4.1.0-20220217  # 指定稳定版本,避免镜像更新导致兼容问题
      alias: hub
    - name: selenium/node-chrome:4.1.0-20220217
      alias: chrome
      environment:
        - SE_EVENT_BUS_HOST=hub
        - SE_EVENT_BUS_PUBLISH_PORT=4442
        - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
    - name: selenium/node-firefox:4.1.0-20220217
      alias: firefox
      environment:
        - SE_EVENT_BUS_HOST=hub
        - SE_EVENT_BUS_PUBLISH_PORT=4442
        - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
  script:
    - npm run wdio  # 确保package.json中已配置该脚本,指向wdio.conf.ts
  artifacts:
    paths:
      - allure-results/  # 若使用Allure报告,可上传报告文件
    when: always

配套wdio.conf.ts配置调整

确保wdio.conf.ts中远程驱动配置指向Selenium Hub:

export const config = {
  // ...其他配置
  hostname: 'hub',  // 对应GitLab CI中service的alias
  port: 4444,
  path: '/wd/hub',
  // ...
  capabilities: [
    {
      browserName: 'chrome',
      // Chrome相关配置
    },
    {
      browserName: 'firefox',
      // Firefox相关配置
    }
  ]
}

补充说明

  1. 根据项目实际Node版本调整node:18-alpine镜像(如node:20-alpine)
  2. 确认package.json中wdio脚本正确:"wdio": "wdio run ./wdio.conf.ts"
  3. Selenium镜像版本建议与本地使用版本一致,避免兼容性问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 07:36:24