├── Dockerfile ├── LICENSE ├── README.md ├── start.sh └── travis.json /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:12.04 2 | RUN apt-get update && apt-get install -y cron && apt-get install -y curl sudo git rsync build-essential wget ruby1.9.1 rubygems1.9.1 python-software-properties && curl -L https://www.opscode.com/chef/install.sh | bash && wget -O - https://github.com/travis-ci/travis-cookbooks/archive/master.tar.gz | tar -xz && mkdir -p /var/chef/cookbooks && cp -a travis-cookbooks-master/ci_environment/* /var/chef/cookbooks 3 | RUN apt-get -y install socat 4 | RUN adduser travis --disabled-password --gecos "" 5 | RUN mkdir /home/travis/builds 6 | ADD travis.json travis.json 7 | RUN locale-gen en_US.UTF-8 8 | ENV LANG en_US.UTF-8 9 | ENV LANGUAGE en_US:en 10 | ENV LC_ALL en_US.UTF-8 11 | RUN chmod 777 /tmp 12 | RUN echo 'travis ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers 13 | RUN chef-solo -o java,xserver,firefox::tarball,chromium -j travis.json 14 | RUN wget http://selenium-release.storage.googleapis.com/2.44/selenium-server-standalone-2.44.0.jar -O selenium-server.jar 15 | ADD start.sh start.sh 16 | CMD bash start.sh 17 | EXPOSE 4444 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Codeception PHP Testing Framework 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SeleniumEnv 2 | =========== 3 | 4 | This is a Docker Image with Selenium Server, Xvfb, Firefox and Chromium installed. SeleniumEnv was created to run Selenium tests without installing Selenium and its dependencies. Selenium server is executed inside a container and connected from a host machine. 5 | 6 | ## Installation 7 | 8 | Grab prepacked [image from a Docker Hub](https://registry.hub.docker.com/u/davert/selenium-env/) 9 | 10 | ``` 11 | docker pull davert/selenium-env 12 | ``` 13 | 14 | 15 | Or build image by yourself. Just clone this repo and run 16 | 17 | ``` 18 | docker build -t selenium-env . 19 | ``` 20 | 21 | you should edit Dockerfile in order to customize version of Selenium Server. 22 | 23 | ## Usage 24 | 25 | SeleniumEnv is able to connect to local or remote web sites. 26 | 27 | ### Accessing Remote Website 28 | 29 | Run the container and bind it to default Selenium port `4444` 30 | 31 | ``` 32 | docker run -i -t -p 4444:4444 davert/selenium-env 33 | ``` 34 | 35 | ### Accessing Local Website by Port 36 | 37 | In case you want to access local website from container you can do the following: 38 | if application is run on localhost (`0.0.0.0`) on a specific port, you can pass `APP_PORT` environment variable into it: 39 | 40 | ``` 41 | php -S 0.0.0.0:8000 & 42 | docker run -i -t -p 4444:4444 -e APP_PORT=8000 davert/selenium-env 43 | ``` 44 | 45 | ### Accessing Local Website by Host 46 | 47 | In case local web site is served by nginx or Apache, and is configured for a specific host, you can pass host name as environment variable: 48 | 49 | ``` 50 | docker run -i -t -p 4444:4444 -e APP_HOST=myapp davert/selenium-env 51 | ``` 52 | 53 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # start Xvfb 4 | if [ ! $RESOLUTION ]; 5 | then 6 | RESOLUTION="1024x768x24" 7 | fi; 8 | 9 | echo "Running Xvfb at $RESOLUTION" 10 | 11 | /usr/bin/Xvfb :99 -ac -screen 0 $RESOLUTION & 12 | export DISPLAY=:99.0 13 | 14 | # get host ip 15 | export HOST_IP=$(/sbin/ip route|awk '/default/ { print $3 }') 16 | 17 | echo "Running Selenium Env: Selenium Server, and Xvfb with Firefox and Chromium" 18 | echo "Host IP: $HOST_IP" 19 | 20 | # adding IP of a host to /etc/hosts 21 | echo "$HOST_IP dockerhost" >> /etc/hosts 22 | 23 | # adding APP_HOST to list of known hosts 24 | if [ $APP_HOST ]; 25 | then 26 | HOSTS=(${APP_HOST//,/ }); 27 | 28 | for i in "${!HOSTS[@]}" 29 | do 30 | echo "Registering host ${HOSTS[i]}" 31 | echo "$HOST_IP ${HOSTS[i]}" >> /etc/hosts 32 | done; 33 | fi; 34 | 35 | # if only port provided - redirect to host+port 36 | if [ $APP_PORT ]; 37 | then 38 | PORTS=(${APP_PORT//,/ }); 39 | 40 | for i in "${!PORTS[@]}" 41 | do 42 | echo "Registering port ${PORTS[i]}" 43 | socat TCP4-LISTEN:${PORTS[i]},fork,reuseaddr TCP4:dockerhost:${PORTS[i]} & 44 | done; 45 | fi; 46 | 47 | # starting selenium 48 | java -jar selenium-server.jar 49 | -------------------------------------------------------------------------------- /travis.json: -------------------------------------------------------------------------------- 1 | {"travis_build_environment":{"user":"travis","group":"travis","home":"\/home\/travis\/","update_hosts":false}} --------------------------------------------------------------------------------