Docker:如何使用selenium服务器做nightwatchJStesting?

我不知道如何使用我的./bundle应用程序来运行selenium服务器,它的文件位于自定义e2e:latest./bundle文件夹中。

我想我必须将selenium服务器和webdriver chrome添加到e2e:latest的Dockerfile中e2e:latest图像,不是吗?

这是我迄今为止所做的:

我用NodeJS和nightwatchJS创build了一个基于java:8-jre的docker镜像:

Dockerfile

 FROM java:8-jre ## Node.js setup RUN curl -sL https://deb.nodesource.com/setup_4.x | bash - RUN apt-get install -y nodejs ## Nightwatch RUN npm install -g nightwatch 

这个图像然后用于testing:

gitlab-ci.yml

 build: stage: build tags: - deploy script: - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - meteor npm install --production - meteor build $PACKAGE_PATH --directory # Maybe something like...? - docker build -t $CI_REGISTRY_IMAGE:e2e . nightwatch: image: e2e:latest stage: e2e tags: - e2e before_script: - cd ./bundle script: - nightwatch 

configuration如下所示:

nightwatch.conf.js

 module.exports = { 'src_folders' : ['test/e2e'], 'output_folder' : 'reports', 'custom_commands_path' : '', 'custom_assertions_path': '', 'page_objects_path' : '', 'globals_path' : '', 'test_runner' : { 'type' : 'mocha', 'options': { 'ui' : 'bdd', 'reporter': 'list' } }, 'selenium': { 'start_process': false, 'server_path' : '', 'log_path' : '', 'host' : '127.0.0.1', 'port' : 4444, 'cli_args' : { 'webdriver.chrome.driver': './bin/chromedriver' } }, 'test_settings': { 'default': { 'launch_url' : 'http://localhost', 'selenium_port': 4444, 'selenium_host': 'localhost', 'silent' : true, 'screenshots' : { 'enabled': true, 'path' : 'reports/error-screenshots' }, 'desiredCapabilities': { 'browserName' : 'chrome', 'javascriptEnabled': true, 'acceptSslCerts' : true } }, 'chrome': { 'desiredCapabilities': { 'browserName' : 'chrome', 'javascriptEnabled': true, 'acceptSslCerts' : true } } } } 

不知道这是否适合Gitlab CI,但看看Selenoid项目。 这是一个小的(6 Mb)二进制文件,可以在不同的Docker容器中启动浏览器,也可以直接启动Webdriver进程。 所以,如果容器的方法不适合你的需求尝试包装Selenoid +例如Chromedriver +铬与Node.js相同的容器。 使用Selenoid时无需安装Java。