验收testing,docker和selenium

我尝试创build一些旨在build立我的JavaScript应用程序的容器。

以下是我需要做的事情:

  • 安装我的依赖关系
  • 开始我的unit testing
  • build立我的项目
  • 开始我的验收testing

这是我的项目dockerfile:

FROM node:6.9 # Enviroment variables ENV HOMEDIR /data RUN mkdir -p ${HOMEDIR} WORKDIR ${HOMEDIR} # install all dependencies ADD package.json ./ RUN npm install # add node content initially ADD . . CMD CI=true npm test && npm run build && npm run test:acceptance 

事实是,当我开始我的验收testing时,我需要使用selenium服务器和phantomjs浏览器。 这样,感谢stackoverflow社区,我创build了一个docker-compose.yml文件,如下所示:

 version: '2' services: hub: image: selenium/hub ports: - "4444:4444" phantomjs: image: akeem/selenium-node-phantomjs depends_on: - hub links: - hub app: build: . depends_on: - hub - phantomjs 

我的selenium幻影很好地连接到我的selenium/集线器,selenium可在我的主机localhost:4444。

我真正的问题是,我的工具来实现验收testing(webdriverio)似乎无法联系selenium服务器,我不知道为什么。

我有以下的堆栈:

 app_1 | [08:24:07] COMMAND POST "/wd/hub/session" app_1 | [08:24:07] DATA {"desiredCapabilities":{"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"maxInstances":5,"browserName":"phantomjs","loggingPrefs":{"browser":"ALL","driver":"ALL"},"requestOrigins":{"url":"http://webdriver.io","version":"4.6.1","name":"webdriverio"}}} app_1 | ERROR: Couldn't connect to selenium server app_1 | phantomjs app_1 | Error: Couldn't connect to selenium server app_1 | app_1 | Wrote xunit report to [./xunit]. 

任何build议?

谢谢你的帮助

如果从另一个容器中运行testing脚本,则需要将wd_host参数设置为http://hub:4444/wd/hub ,而不是http://localhost:4444/wd/hub (默认值) 。

links:字段使得hub在主机名hub下可用,而不是作为localhost到另一容器。

ports:字段仅用于从主机访问容器,不影响容器本身可以访问的容器。