如何在 gitlab 上为 nightwatch e2e 测试设置正确的 Selenium 主机?

How to set correct Selenium host for nightwatch e2e test on gitlab?

我想为我的 vue.js 应用程序和管道中的 运行 添加一些端到端测试。 我的gitlab-ci.yml中对应的部分是这样的:

e2e:
image: node:8
before_script:
  - npm install
services:
  - name: selenium/standalone-chrome
  alias: chrome
stage: testing
script:
  - cd online-leasing-frontend
  - npm install
  - npm run test:e2e

还有我的 nightwatch.js 配置:

{
  "selenium": {
    "start_process": false
    },
  "test_settings": {
    "default": {
      "selenium_port": 4444,
      "selenium_host": "chrome"
    }
  }
}

“selenium_host”:“chrome”是将主机设置为selenium服务的正确方法吗? 我收到以下错误,表明我的 e2e 测试无法连接到 selenium 服务:

连接被拒绝! selenium 服务器启动了吗?

有什么建议吗?

在 Selenium Repo 上它说: "When executing docker run for an image with Chrome or Firefox please either mount -v /dev/shm:/dev/shm or use the flag --shm-size=2g to use the host's shared memory." 我不太了解 gitlab-ci ,但恐怕无法将其作为参数添加到服务中。

问题是,根据 this issue,Gitlab CI 使用 Kubernetes Executor 而不是 Docker Executor 将所有服务映射到 127.0.0.1 .将 selenium_host 设置为该地址后,一切正常。

{
  "selenium": {
    "start_process": false
    },
  "test_settings": {
    "default": {
      "selenium_port": 4444,
       "selenium_host": "127.0.0.1",
    }
  }
}