docker - 在 alpine docker 容器上运行 selenium 测试时出错
问题描述
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
解决方案
也许您必须等待硒容器启动?
查看本指南: https ://github.com/SeleniumHQ/docker-selenium#waiting-for-the-grid-to-be-ready
写下一个脚本来检查“准备好”:真,
推荐阅读
- localhost - 创建自己的本地 Java 身份提供者 SAML2
- python - Check and remove duplicates in python MongoDB
- javascript - how to stop/recheck data in forEach using Nodejs
- r - 使用 R 为字符串中的字母模式赋值
- vue.js - Vue memory leak: each time v-if value is changed, more memory is needed
- angularjs - 使用 AngularJS 登录 Google
- excel - if cell(C2) l contains '@", remove the domain text + "@", else, output original value(C2) / check one cell against many string groups
- angular - 如何使用 Angular 4 将占位符放在选择下拉列表中?
- python - 根据值拆分熊猫数据框
- php - How can i fetch data from my requests table and put it in users table