Create Dockerfile that includes Firefox and Chrome drivers for Selenium

让人想犯罪 __ 提交于 2019-12-13 00:34:56

问题


I have the following Dockerfile which will build a Selenium server

FROM selenium/standalone-firefox:3.4.0-chromium
FROM selenium/standalone-chrome

USER root
ENV NODE_ENV test

RUN mkdir -p /usr/local/cdt-tests/csv-data
COPY ./csv-data /usr/local/cdt-tests/csv-data
USER seluser

obviously the two FROM statements is incorrect => How can I create a Selenium server container that has both a Chrome driver and Firefox driver for Selenium. As far as I can tell, the selenium/standalone-firefox:3.4.0-chromium image only works for Firefox.


回答1:


There is no inheritance type setup for Dockerfiles like you are suggesting.

To implement a combined build you would need find the common FROM ancestor of the standalone-firefox and standalone-chrome, which is selenium/node-base and create your own Docker file to reapply all the build steps that selenium/standalone-chrome applies. Then keep it in sync whenever Selenium update their builds.

Dockerfile Hierarchy:

                selenium/node-base
                /               \
selenium/node-chrome          selenium/node-firefox
               |                 |
selenium/standalone-chrome    selenium/standalone-firefox

The problem is these builds have been designed to be seperate, so there is significant overlap in the variables and settings that the images use that you would also need to unpick in your custom build to control and run both chrome and firefox at the same time. You will probably end up having to do everything from scratch.

Selenium Grid

Running individual Selenium grid node's behind a grid hub is the standard way to do multi browser testing from a single endpoint. You can run Firefox, Chrome or Phantom JS nodes in Docker or connect standard nodes from anywhere else.

Poor mans grid

You can always run a container for Chrome and Firefox on seperate ports and point the same test suite at a different port if setting up a Grid is a lot of work for the simple case of running some tests against each browser.




回答2:


You cannot merge two docker files likes that. You can use one as a base for your docker file, then copy the important bits from the other into your one.

However you shouldn't really need to. There are images out there with multiple browsers and drivers included. Or better, you could set up a grid with the hub image and some driver images.

You might even consider a library such as Serenity or a product such as Katalon, both of which do it all for you. There is even a Katalon docker image designed for use in CI: it's command-line + headless only, but that's all you need for most of your CI-driven regression testing.



来源:https://stackoverflow.com/questions/47145325/create-dockerfile-that-includes-firefox-and-chrome-drivers-for-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!