Docker, ubuntu 14.04, selenium and chrome browser

4,120 views
Skip to first unread message

sami.sa...@q-factory.fi

unread,
Jul 19, 2017, 5:46:42 AM7/19/17
to robotframework-users
Hi,

I have tried to setup Dockerfile and run script for alternative browsing with Chrome for testing web pages with Selenium.
Do I need selenium standalone server if i have selenium installed to Ubuntu? Or is chromedriver enough? How this is working with Chrome.

I have Docker image with Ubuntu 14.04 and I try to setup Chrome, but browser is not opened with this kind of setup:

Dockerfile:

FROM ubuntu:14.04

RUN adduser --disabled-password --gecos '' user
RUN adduser user sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

USER user

# Install old version of firefox + dependencies
RUN    sudo apt-get update --fix-missing && \
    sudo apt
-get install -y wget libgtk-3-0 libasound2 libdbus-glib-1-2 \
    git python
-pip make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl \
    x11vnc xvfb

RUN    sudo apt-get purge firefox

# Install old version of firefox
RUN sudo wget -O firefox-mozilla-build_46.0.1-0ubuntu1_amd64.deb 'https://sourceforge.net/projects/ubuntuzilla/files/mozilla/apt/pool/main/f/firefox-mozilla-build/firefox-mozilla-build_46.0.1-0ubuntu1_amd64.deb'
RUN sudo dpkg -i firefox-mozilla-build_46.0.1-0ubuntu1_amd64.deb

# Install new version of firefox with geckodriver
# RUN sudo wget -O firefox-mozilla-build_ubuntu1_amd64.deb 'https://sourceforge.net/projects/ubuntuzilla/files/mozilla/apt/pool/main/f/firefox-mozilla-build/firefox-mozilla-build_52.0.2-0ubuntu1_amd64.deb'
# RUN sudo dpkg -i firefox-mozilla-build_ubuntu1_amd64.deb

# Geckodriver: Download, unarchive and move to PATH
# RUN sudo wget -O geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v0.15.0/geckodriver-v0.15.0-linux64.tar.gz
# RUN sudo tar -xzvf geckodriver.tar.gz
# RUN mkdir $HOME/drivers
# RUN sudo mv geckodriver $HOME/drivers
# RUN sudo chmod -R 777 $HOME/drivers
# ENV PATH="/home/user/drivers:${PATH}"

# Install dependencies.
RUN sudo apt-get update
RUN sudo apt-get install -y openjdk-7-jre-headless xvfb libxi6 libgconf-2-4 unzip

# Install Chrome.
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
RUN sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN sudo apt-get update
RUN sudo apt-get install -y google-chrome-stable

# Install ChromeDriver.
RUN wget -N http://chromedriver.storage.googleapis.com/2.27/chromedriver_linux64.zip -P ~/
RUN unzip ~/chromedriver_linux64.zip -d ~/
RUN rm ~/chromedriver_linux64.zip
RUN sudo mv -f ~/chromedriver /usr/local/share/
RUN sudo chmod +x /usr/local/share/chromedriver
RUN sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver

# Install Selenium. Do I Need Selenium-server if I have installed selenium to Ubuntu???!!!
RUN sudo wget -N http://selenium-release.storage.googleapis.com/3.0/selenium-server-standalone-3.0.1.jar -P ~/
RUN sudo mv -f ~/selenium-server-standalone-3.0.1.jar /usr/local/share/
RUN sudo chmod +x /usr/local/share/selenium-server-standalone-3.0.1.jar
RUN sudo ln -s /usr/local/share/selenium-server-standalone-3.0.1.jar /usr/local/bin/selenium-server-standalone-3.0.1.jar

# Install Pyenv
RUN sudo apt-get install -y git python-pip make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl python-tk tk-dev
RUN sudo pip install virtualenvwrapper

ENV HOME        /home/user

RUN git clone https://github.com/yyuu/pyenv.git $HOME/.pyenv
RUN git clone https://github.com/yyuu/pyenv-virtualenvwrapper.git $HOME/.pyenv/plugins/pyenv-virtualenvwrapper
RUN git clone https://github.com/yyuu/pyenv-virtualenv.git $HOME/.pyenv/plugins/pyenv-virtualenv

ENV PYENV_ROOT  $HOME/.pyenv
ENV PATH        $PYENV_ROOT/bin:$PATH

RUN python --version

# Install python versions you want under here
RUN pyenv install 2.7.13
RUN pyenv rehash

# Set the default python version you want to use
ENV PYTHON_VERSION  2.7.13

RUN pyenv global $PYTHON_VERSION

RUN pyenv versions
RUN pyenv global

RUN eval "$(pyenv init -)"
RUN eval "$(pyenv virtualenv-init -)"

# These pip modules are used with older firefox
# RUN $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install --upgrade pip && \
   
# $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install requests && \
   
# $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install robotframework robotframework-selenium2library selenium==2.53.6 robotframework-xvfb robotframework-extendedselenium2library && \
   
# $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install robotframework-imaplibrary==0.3.0 robotframework-requests robotframework-sudslibrary beautifulsoup4
    # $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install robotframework robotframework-selenium2library selenium==2.53.6 robotframework-xvfb robotframework-extendedselenium2library

# These pip modules are used with latest firefox

RUN $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install --upgrade pip && \
    $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install requests && \
    $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install robotframework robotframework-selenium2library selenium==3.3.0 robotframework-xvfb robotframework-extendedselenium2library && \
    $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install robotframework-imaplibrary==0.3.0 robotframework-requests robotframework-sudslibrary beautifulsoup4


RUN mkdir ~/.vnc
RUN x11vnc  -storepasswd 1234 ~/.vnc/passwd

COPY run.sh /usr/local/bin/run.sh
RUN sudo chmod +x /usr/local/bin/run.sh

CMD ["run.sh"]


The I try to start Chrome in run.sh but I cannot get Chrom browser open with Robot keyword: 
Open Browser    ${url}    browser=chrome

run.sh script for Xvfb looks like this for Chrome:
xvfb-run -ac --server-args='-screen 0, ${RES}' google-chrome -start-maximized > /dev/null 2>&1 &

Working Xvfb line in run.sh with Firefox is like this:
Xvfb ${DISPLAY} -screen 0 ${RES} -ac > /dev/null 2>&1 &

How I could "replace" Firefox with Chrome? 

I would be appreciated of your help.

Cheers
Sami



Kevin O.

unread,
Jul 25, 2017, 10:50:14 AM7/25/17
to robotframework-users
I have had success starting from the Selenium Docker containers.
https://github.com/SeleniumHQ/docker-selenium

This would simplify your setup as Selenium & VNC (the debug containers) would be already setup for you.

sami.sa...@q-factory.fi

unread,
Jul 26, 2017, 1:01:35 AM7/26/17
to robotframework-users
Hi Kevin,

Thanks for your message.
Are you using standalone containers or nodes with hub? 

I have started also to plan and try our environment with these Selenium Docker containers.

-Sami

Kevin O.

unread,
Jul 27, 2017, 1:17:42 PM7/27/17
to robotframework-users
Using standalone for now.
Thinking about trying Zalenium.

sami.sa...@q-factory.fi

unread,
Sep 12, 2017, 2:04:27 AM9/12/17
to robotframework-users
SOLVED!!! I changed to Ubuntu 16.04 and using latest stable chrome in container. Also Selenium hub+chrome container works now. Here is our Dockerfile, where FF and Chrome have been installed inside and works.

FROM ubuntu:16.04
ENV TZ 'Europe/Helsinki'
RUN echo $TZ > /etc/timezone && \
    apt
-get update && apt-get install -y tzdata && \
    rm
/etc/localtime && \
    ln
-snf /usr/share/zoneinfo/$TZ /etc/localtime && \
    dpkg
-reconfigure -f noninteractive tzdata && \
    apt
-get clean

RUN apt-get update && apt-get install -y sudo && rm -rf /var/lib/apt/lists/*

#RUN ln -snf /bin/bash /bin/sh

RUN adduser --disabled-password --gecos '' user
RUN adduser user sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

USER user

#RUN   sudo apt-get update --fix-missing

# Install old version of firefox + dependencies
#RUN   sudo apt-get install -y wget libgtk-3-0 libasound2 libdbus-glib-1-2
RUN    sudo apt-get update --fix-missing && \
    sudo apt-get install
-y wget libgtk-3-0 libasound2 libdbus-glib-1-2 \
    git python-pip make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl \
    x11vnc xvfb

RUN    sudo apt-get purge firefox

# Install old version of firefox
# RUN sudo wget -O firefox-mozilla-build_46.0.1-0ubuntu1_amd64.deb 'https://sourceforge.net/projects/ubuntuzilla/files/mozilla/apt/pool/main/f/firefox-mozilla-build/firefox-mozilla-build_46.0.1-0ubuntu1_amd64.deb'
# RUN sudo dpkg -i firefox-mozilla-build_46.0.1-0ubuntu1_amd64.deb

# Install latest version of firefox 55.x with geckodriver
RUN sudo apt-get install -y wget libgtk-3-0 libasound2 libdbus-glib-1-2 libxss1 fonts-liberation libappindicator1 lsb-release xdg-utils

RUN sudo wget -O firefox-mozilla-build_ubuntu1_amd64.deb 'https://sourceforge.net/projects/ubuntuzilla/files/mozilla/apt/pool/main/f/firefox-mozilla-build/firefox-mozilla-build_55.0.2-0ubuntu1_amd64.deb'
RUN sudo dpkg -i firefox-mozilla-build_ubuntu1_amd64.deb

# Geckodriver: Download, unarchive and move to PATH
RUN sudo wget -O geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v0.18.0/geckodriver-v0.18.0-linux64.tar.gz
RUN sudo tar -xzvf geckodriver.tar.gz
RUN mkdir $HOME/drivers
RUN sudo mv geckodriver $HOME/drivers
RUN sudo chmod -R 777 $HOME/drivers
ENV PATH="/home/user/drivers:${PATH}"

##### Install Chrome and ChromeDriver  #####
ENV CHROME_DRIVER_VERSION                                 2.31
RUN sudo apt-get install -y unzip openjdk-8-jre-headless xvfb libxi6 libgconf-2-4

# Install Chrome
RUN wget -N https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -P ~/
RUN sudo dpkg -i --force-depends ~/google-chrome-stable_current_amd64.deb
RUN sudo apt-get -f install -y
RUN sudo dpkg -i --force-depends ~/google-chrome-stable_current_amd64.deb

# Install ChromeDriver
RUN wget -N http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P ~/
RUN unzip ~/chromedriver_linux64.zip -d ~/
RUN rm ~/chromedriver_linux64.zip
RUN sudo mv -f ~/chromedriver /usr/local/bin/chromedriver
RUN sudo chown root:root /usr/local/bin/chromedriver
RUN sudo chmod 0755 /usr/local/bin/chromedriver

# Install Pyenv
RUN sudo apt-get install -y git python-pip make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl python-tk tk-dev
RUN sudo pip install virtualenvwrapper

ENV HOME        /home/user

RUN git clone https://github.com/yyuu/pyenv.git $HOME/.pyenv
RUN git clone https://github.com/yyuu/pyenv-virtualenvwrapper.git $HOME/.pyenv/plugins/pyenv-virtualenvwrapper
RUN git clone https://github.com/yyuu/pyenv-virtualenv.git $HOME/.pyenv/plugins/pyenv-virtualenv

ENV PYENV_ROOT  $HOME/.pyenv
ENV PATH        $PYENV_ROOT/bin:$PATH

RUN python --version

# Install python versions you want under here
# RUN pyenv install 2.7.12
RUN pyenv install 2.7.13
RUN pyenv rehash

# Set the default python version you want to use
# ENV PYTHON_VERSION  2.7.12
ENV PYTHON_VERSION  2.7.13

RUN pyenv global $PYTHON_VERSION

RUN pyenv versions
RUN pyenv global

RUN eval "$(pyenv init -)"
RUN eval "$(pyenv virtualenv-init -)"

# These pip modules are used with older firefox
# RUN $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install --upgrade pip && \
    # $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install requests && \
    # $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install robotframework robotframework-selenium2library selenium==2.53.6 robotframework-xvfb robotframework-extendedselenium2library && \
   # $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install robotframework-imaplibrary==0.3.0 robotframework-requests robotframework-sudslibrary beautifulsoup4 xvfbwrapper robotframework-xvfb
    ## $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install robotframework robotframework-selenium2library selenium==2.53.6 robotframework-xvfb robotframework-extendedselenium2library

# These pip modules are used with latest firefox

RUN $HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install --upgrade pip && \
    $
HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install requests &&
\
    $
HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install robotframework robotframework-selenium2library selenium==3.5.0 robotframework-xvfb && \
   $
HOME/.pyenv/versions/$PYTHON_VERSION/bin/pip install robotframework-imaplibrary==0.3.0 robotframework-requests robotframework-sudslibrary beautifulsoup4 xvfbwrapper robotframework-xvfb

#RUN sudo apt-get install -y x11vnc xvfb

RUN mkdir ~/.vnc
RUN x11vnc  -storepasswd 1234 ~/.vnc/passwd

#ADD run.sh /usr/local/bin/run.sh
COPY run.sh /usr/local/bin/run.sh
RUN sudo chmod +x /usr/local/bin/run.sh

# There seems to be a bug in Selenium and a line needs to be removed from Seleniums webdriver.py
# Apparently is fixed in selenium server 3.5.1, but that's not included in selenium-docker yet
# See: https://github.com/SeleniumHQ/selenium/issues/3808
RUN sed -i -e 's/"capabilities": w3c_caps,//g' $HOME/.pyenv/versions/$PYTHON_VERSION/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py

CMD ["run.sh"]
Reply all
Reply to author
Forward
0 new messages