在 alpine docker 容器上运行 selenium 测试时出错

Posted

技术标签:

【中文标题】在 alpine docker 容器上运行 selenium 测试时出错【英文标题】:Error on Running selenium test on alpine docker container 【发布时间】:2019-01-14 12:23:39 【问题描述】:

Dockerfile:

FROM node:8.14.1-alpine

RUN apk update && apk add --no-cache openjdk8-jre
RUN apk update && apk add python py-pip curl unzip libexif udev nano

ENV CHROME_BIN=/usr/bin/chromium-browser
RUN echo @v3.8 http://nl.alpinelinux.org/alpine/v3.8/community >> /etc/apk/repositories && \
    echo @v3.8 http://nl.alpinelinux.org/alpine/v3.8/main >> /etc/apk/repositories && \
    apk add --no-cache \
    chromium@v3.8 \
    nss@v3.8

# Tell Puppeteer to skip installing Chrome. We'll be using the installed package.
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

WORKDIR /project_compile/vue_app

COPY vue_app /project_compile/vue_app
RUN rm -rf node_modules

RUN npm config set registry http://registry.npmjs.org/ && npm install

CMD npm run test:e2e:headless

运行时出现这个错误:

Error retrieving a new session from the selenium server

Connection refused! Is selenium server started?
 value: 
    message: 'Timed out waiting for driver server to start.\nBuild info: version: \'3.141.59\', revision: \'e82be7d358\', time: \'2018-11-14T08:25:53\'\nSystem info: host: \'a3f993cb3a2b\', ip: \'172.22.0.2\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'4.15.0-33-generic\', java.version: \'1.8.0_191\'\nDriver info: driver.version: unknown',
     error: 'unknown error' ,
  status: 13 

 ERROR  Error: Command failed: /project_compile/vue_app/node_modules/nightwatch/bin/nightwatch --config nightwatch.conf.js --env chrome
Error: Command failed: /project_compile/vue_app/node_modules/nightwatch/bin/nightwatch --config nightwatch.conf.js --env chrome
    at makeError (/project_compile/vue_app/node_modules/execa/index.js:174:9)
    at Promise.all.then.arr (/project_compile/vue_app/node_modules/execa/index.js:278:16)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vue_app@0.1.0 test:e2e:headless: `vue-cli-service test:e2e --config nightwatch.conf.js --env chrome`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the vue_app@0.1.0 test:e2e:headless script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-01-14T12_14_57_744Z-debug.log

似乎 chrome 工作正常(可测试运行类似 chromium-browser --headless --no-sandbox --dump-dom https://www.chromestatus.com/),而且 selenium 似乎工作正常。

为什么测试没有运行?错误无法解释。

所有代码都包含在此 repo https://github.com/nicolalandro/vue-selenium-docker 中。所以复制它很容易 - 克隆 repo 并运行两个命令:

docker-compose -f docker/test/js/docker-compose-js-e2e.yml 构建 docker-compose -f docker/test/js/docker-compose-js-e2e.yml up --exit-code-from e2e

【问题讨论】:

【参考方案1】:

也许您必须等待硒容器启动?

查看本指南: https://github.com/SeleniumHQ/docker-selenium#waiting-for-the-grid-to-be-ready

编写一个脚本来检查 "ready": true,

【讨论】:

【参考方案2】:

问题在于 selenium 版本与 chrome 版本不一致。

【讨论】:

以上是关于在 alpine docker 容器上运行 selenium 测试时出错的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Docker 中的 Alpine 上运行 Apache 2?

无法在基于 Alpine 的 Docker 容器中运行 Play 框架应用程序

在 Alpine Docker 容器上安装 OpenSSH

无法使用 node:alpine 在 Docker 容器中运行 React 应用程序的开发版本

在 Alpine Docker 容器中运行 OpenSSH

如何在 Alpine Docker 容器中运行 Bash 脚本?