【问题标题】:Issue when trying to run Webdriver IO (end to end) tests in a Gitlab CI pipeline runner using a docker image尝试使用 docker 映像在 Gitlab CI 管道运行器中运行 Webdriver IO(端到端)测试时出现问题
【发布时间】:2020-09-13 17:52:41
【问题描述】:

这是我第一次在这个平台上发帖,如果我的请求缺少信息,请告诉我,以便我提供。

我正在尝试使用 Webdriver IO 运行我的端到端测试,我一开始一直在本地运行我的测试,但现在我需要使用 docker 映像在 Gitlab CI 管道中执行它们,这里有一些信息关于设置:

Docker 镜像:

  • 这是一个 alpinedocker 映像
  • 节点版本:12.18.3
  • npm 版本:6.14.6
  • Java 版本:openjdk "11.0.8"
  • 铬:85.0.4183.83
  • Mozilla:80.0.1

Webdriver IO 配置:

  • 最新版本的 webdriver IO 框架、geckodriver 和 wdio-geckodriver-service 这是我的 wdio.cong.js 文件
const { generate } = require('multiple-cucumber-html-reporter');
const { removeSync } = require('fs-extra');
exports.config = {
  runner: 'local',
  maxInstances: 1,
  capabilities: [
    {
      maxInstances: 1,
      browserName: 'firefox',
      acceptInsecureCerts: true,
      'moz:firefoxOptions': {
        args: ['--headless', '--lang=fr-FR', '--disable-dev-shm-usage']
      }
    }
  ],
  specs: ['./features/adminNavigation.feature'],

  logLevel: 'info',

  bail: 0,

  baseUrl: 'http://localhost:3000',

  waitforTimeout: 10000000,

  connectionRetryTimeout: 120000,

  connectionRetryCount: 3,

  services: ['geckodriver'],

  framework: 'cucumber',

  reporters: [
    [
      'cucumberjs-json',
      {
        jsonFolder: './cucumberjs-reports/json',
        language: 'en'
      }
    ]
  ],

  cucumberOpts: {
    timeout: 40000,
    requireModule: [
      'tsconfig-paths/register',
      () => {
        require('ts-node').register({ files: true, project: './tsconfig.json' });
      }
    ],
    require: ['./**/**/*.step.ts']
  },
  onPrepare: function(config, capabilities) {
    removeSync('./cucumberjs-reports');
  },
  onComplete: function(exitCode, config, capabilities, results) {
    generate({
      jsonDir: './cucumberjs-reports/json',
      reportPath: './cucumberjs-reports/report'
    });
  }
};


我的 package.json:

    "geckodriver": "^1.20.0",
    "@wdio/cli": "^6.4.5",
    "@wdio/cucumber-framework": "^6.4.3",
    "@wdio/local-runner": "^6.4.5",
    "@wdio/mocha-framework": "^6.4.0",
    "@wdio/selenium-standalone-service": "^6.4.7",
    "@wdio/spec-reporter": "^6.4.0",
    "@wdio/sync": "^6.4.5",
    "chromedriver": "^85.0.1",
    "wdio-chromedriver-service": "^6.0.4",
    "wdio-cucumberjs-json-reporter": "^2.0.2",
    "wdio-geckodriver-service": "^1.1.0",

这是错误日志:

Execution of 1 spec files started at 2020-09-11T13:15:06.515Z
2062020-09-11T13:15:06.519Z DEBUG @wdio/utils:initialiseServices: initialise service "geckodriver" as NPM package
2072020-09-11T13:15:06.522Z INFO @wdio/cli:launcher: Run onPrepare hook
2082020-09-11T13:15:06.525Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2092020-09-11T13:15:06.535Z INFO @wdio/local-runner: Start worker 0-0 with arg: ./apps/front-e2e-wdio/wdio.ci.conf.js
210[0-0] 2020-09-11T13:15:07.117Z INFO @wdio/local-runner: Run worker command: run
211[0-0] 2020-09-11T13:15:07.247Z DEBUG @wdio/local-runner:utils: init remote session
212[0-0] 2020-09-11T13:15:07.252Z INFO webdriverio: Initiate new session using the ./protocol-stub protocol
213[0-0] RUNNING in firefox - /apps/front-e2e-wdio/features/adminNavigation.feature
214[0-0] 2020-09-11T13:15:07.749Z DEBUG @wdio/utils:initialiseServices: initialise service "geckodriver" as NPM package
215[0-0] 2020-09-11T13:15:07.772Z DEBUG @wdio/local-runner:utils: init remote session
216[0-0] 2020-09-11T13:15:07.774Z INFO webdriverio: Initiate new session using the webdriver protocol
217[0-0] 2020-09-11T13:15:07.778Z INFO webdriver: [POST] http://localhost:34305/session
218[0-0] 2020-09-11T13:15:07.778Z INFO webdriver: DATA {
219 capabilities: {
220 alwaysMatch: {
221 browserName: 'firefox',
222 acceptInsecureCerts: true,
223 'moz:firefoxOptions': [Object]
224 },
225 firstMatch: [ {} ]
226 },
227 desiredCapabilities: {
228 browserName: 'firefox',
229 acceptInsecureCerts: true,
230 'moz:firefoxOptions': { args: [Array] }
231 }
232}
233[0-0] 2020-09-11T13:15:10.623Z DEBUG webdriver: request failed due to response error: unknown error
234[0-0] 2020-09-11T13:15:10.624Z INFO webdriver: Retrying 1/3
2352020-09-11T13:15:10.624Z INFO webdriver: [POST] http://localhost:34305/session
2362020-09-11T13:15:10.624Z INFO webdriver: DATA {
237 capabilities: {
238 alwaysMatch: {
239 browserName: 'firefox',
240 acceptInsecureCerts: true,
241 'moz:firefoxOptions': [Object]
242 },
243 firstMatch: [ {} ]
244 },
245 desiredCapabilities: {
246 browserName: 'firefox',
247 acceptInsecureCerts: true,
248 'moz:firefoxOptions': { args: [Array] }
249 }
250}
251[0-0] 2020-09-11T13:15:10.623Z WARN webdriver: Request failed with status 500 due to invalid argument: can't kill an exited process
252[0-0] 2020-09-11T13:15:13.141Z DEBUG webdriver: request failed due to response error: unknown error
253[0-0] 2020-09-11T13:15:13.142Z WARN webdriver: Request failed with status 500 due to invalid argument: can't kill an exited process
254[0-0] 2020-09-11T13:15:13.142Z INFO webdriver: Retrying 2/3
255[0-0] 2020-09-11T13:15:13.143Z INFO webdriver: [POST] http://localhost:34305/session
256[0-0] 2020-09-11T13:15:13.143Z INFO webdriver: DATA {
257 capabilities: {
258 alwaysMatch: {
259 browserName: 'firefox',
260 acceptInsecureCerts: true,
261 'moz:firefoxOptions': [Object]
262 },
263 firstMatch: [ {} ]
264 },
265 desiredCapabilities: {
266 browserName: 'firefox',
267 acceptInsecureCerts: true,
268 'moz:firefoxOptions': { args: [Array] }
269 }
270}
271[0-0] 2020-09-11T13:15:15.558Z DEBUG webdriver: request failed due to response error: unknown error
272[0-0] 2020-09-11T13:15:15.567Z INFO webdriver: Retrying 3/3
273[0-0] 2020-09-11T13:15:15.567Z INFO webdriver: [POST] http://localhost:34305/session
274[0-0] 2020-09-11T13:15:15.568Z INFO webdriver: DATA {
275 capabilities: {
276 alwaysMatch: {
277 browserName: 'firefox',
278 acceptInsecureCerts: true,
279 'moz:firefoxOptions': [Object]
280 },
281 firstMatch: [ {} ]
282 },
283 desiredCapabilities: {
284 browserName: 'firefox',
285 acceptInsecureCerts: true,
286 'moz:firefoxOptions': { args: [Array] }
287 }
288}
289[0-0] 2020-09-11T13:15:15.566Z WARN webdriver: Request failed with status 500 due to invalid argument: can't kill an exited process
290[0-0] 2020-09-11T13:15:17.985Z DEBUG webdriver: request failed due to response error: unknown error
291[0-0] 2020-09-11T13:15:17.986Z ERROR webdriver: Request failed with status 500 due to unknown error: invalid argument: can't kill an exited process
2922020-09-11T13:15:17.986Z ERROR webdriver: unknown error: invalid argument: can't kill an exited process
293 at getErrorFromResponseBody (/builds/node_modules/webdriver/build/utils.js:121:10)
294 at WebDriverRequest._request (/builds/node_modules/webdriver/build/request.js:149:56)
295 at processTicksAndRejections (internal/process/task_queues.js:97:5)
296 at async startWebDriverSession (/builds/node_modules/webdriver/build/utils.js:41:16)
297 at async Function.newSession (/builds/node_modules/webdriver/build/index.js:44:23)
298 at async remote (/builds/node_modules/webdriverio/build/index.js:75:20)
299 at async Runner._startSession (/builds/node_modules/@wdio/runner/build/index.js:206:50)
300 at async Runner._initSession (/builds/node_modules/@wdio/runner/build/index.js:175:21)
301 at async Runner.run (/builds/node_modules/@wdio/runner/build/index.js:93:15)
3022020-09-11T13:15:17.987Z ERROR @wdio/runner: Error: Failed to create session.
303invalid argument: can't kill an exited process
304 at startWebDriverSession (/builds/node_modules/webdriver/build/utils.js:45:11)
305 at processTicksAndRejections (internal/process/task_queues.js:97:5)
306[0-0] Error: Failed to create session.
307invalid argument: can't kill an exited process
3082020-09-11T13:15:18.108Z DEBUG @wdio/local-runner: Runner 0-0 finished with exit code 1
309[0-0] FAILED in firefox - /apps/front-e2e-wdio/features/adminNavigation.feature
3102020-09-11T13:15:18.110Z INFO @wdio/cli:launcher: Run onComplete hook
3112020-09-11T13:15:18.112Z ERROR @wdio/cli:utils: Error in onCompleteHook: Error: There were issues reading JSON-files from './apps/front-e2e-wdio/cucumberjs-reports/json'.
312 at collectJSONS (/builds/node_modules/multiple-cucumber-html-reporter/lib/collect-jsons.js:16:15)
313 at generateReport (/builds/node_modules/multiple-cucumber-html-reporter/lib/generate-report.js:69:22)
314 at Object.onComplete (/builds/apps/front-e2e-wdio/wdio.ci.conf.js:44:5)
315 at /builds/node_modules/@wdio/cli/build/utils.js:109:13
316 at Array.map (<anonymous>)
317 at runOnCompleteHook (/builds/node_modules/@wdio/cli/build/utils.js:107:37)
318 at Launcher.run (/builds/node_modules/@wdio/cli/build/launcher.js:83:69)
319 at processTicksAndRejections (internal/process/task_queues.js:97:5)
320Spec Files: 0 passed, 1 failed, 1 total (100% completed) in 00:00:11 
3212020-09-11T13:15:18.114Z INFO @wdio/local-runner: Shutting down spawned worker
3222020-09-11T13:15:18.365Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
3232020-09-11T13:15:18.366Z INFO @wdio/local-runner: shutting down


编辑 我用来运行测试的命令如下:“npx wdio wdio.conf.js”。

这是我正在使用的 Docker 配置文件:

FROM alpine:latest

ARG BUILD_DATE
ARG VCS_REF

USER root

# Install node
RUN apk add --update nodejs npm

# Installs latest Chromium package.
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories \
    && echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
    && echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
    && echo "http://dl-cdn.alpinelinux.org/alpine/v3.11/main" >> /etc/apk/repositories \
    && apk upgrade -U -a \
    && apk add --no-cache \
    libstdc++ \
    chromium \
    harfbuzz \
    nss \
    freetype \
    ttf-freefont \
    wqy-zenhei \
    && rm -rf /var/cache/* \
    && mkdir /var/cache/apk

# Add Chrome as a user
RUN mkdir -p /usr/src/app \
    && adduser -D chrome \
    && chown -R chrome:chrome /usr/src/app
# Run Chrome as non-privileged
USER chrome
WORKDIR /usr/src/app

ENV CHROME_BIN=/usr/bin/chromium-browser \
    CHROME_PATH=/usr/lib/chromium/

USER root
# Install firefox
RUN apk upgrade --update-cache --available
RUN apk add xvfb firefox dbus py-pip ttf-dejavu

ENV FIREFOX_BIN=/usr/bin/firefox

# Install bash && curl
RUN apk add --no-cache bash
RUN apk --no-cache add curl

#ADD wait module
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.2.1/wait /wait
RUN chmod +x /wait

# Install Mongo Tools
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.9/community' >> /etc/apk/repositories
RUN apk add mongodb-tools

# Install jdk11
RUN apk --no-cache add openjdk11 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community

# Install chromeDriver
RUN apk add --no-cache chromium-chromedriver

RUN ls

RUN node -v
RUN npm -v
RUN java -version
RUN chromium-browser --version
RUN firefox --version
# RUN apt-cache policy chromium | grep Installed | sed -e "s/Installed/Chrome/"

CMD tail -f /dev/null  

【问题讨论】:

  • 最好显示 dockerfile 的内容和如何运行测试的命令
  • @ujlbu4 您好,我添加了您要求的信息,您可以查看一下
  • 本地运行时测试是否运行成功?根据您的日志,由于某些配置问题,它无法创建 WebDriver session。可能是一些version incompatibilities 或者只是配置错误。你的本地运行成功了吗?
  • @ujlbu4 嗨,感谢您的评论。是的,它在 chrome、firfox 和无头模式下也能在本地完美运行。你说得对,这可能是我正在调查的兼容性问题。
  • @NizarSF 您是否从同一个 docker 映像中本地运行它们?如果没有,那就试试吧。

标签: docker gitlab-ci webdriver-io


【解决方案1】:

请参阅 repo https://gitlab.com/bar_foo/wdio-cucumber-typescript 以获取有关如何在 GitLab 管道中的 Chrome 和 Firefox 中运行测试的示例。

注意:如果您决定使用devtools 自动化协议而不是webdriver 协议,则图像中不需要Java,请参阅https://webdriver.io/blog/2019/09/16/devtools.html

【讨论】:

  • G 感谢您的回答,我尝试了您的设置,但是我有一个关于 Firefox 安装命令的问题。我使用 alpine 作为基础映像,我无法真正更改它,所以我继续更改命令(apt-get 不存在)以使其工作,但我在安装这些软件包时遇到问题(apt-获取 -qqy 安装 libx11-xcb1 libxt-dev libgtk-3-bin libdbus-glib-1-2)。您发现的这些依赖项是否在图像上丢失了?我试图在 alpine 中找到这些包的等价物,但我不知道这些是否真的能解决我的问题。
  • 这些是火狐浏览器所需的软件包。您在容器中安装后是否尝试过运行 Firefox?它会抛出什么错误?
  • 问候,我尝试了您的设置,但起初它没有工作,然后我决定尝试在 docker 映像中运行我的测试,这很成功,使我能够找到 firefox 浏览器和geckodriver,但即便如此它在 gitlabCi 上不起作用,我认为如果我设法让它在我的 docker 容器上工作,问题就会得到解决。
猜你喜欢
  • 1970-01-01
  • 2021-08-19
  • 1970-01-01
  • 2022-10-24
  • 1970-01-01
  • 2019-09-05
  • 1970-01-01
  • 2021-10-04
  • 2020-11-22
相关资源
最近更新 更多