Skip to content

DockerFile to set up protractor

Trisha Chetani edited this page Feb 16, 2018 · 2 revisions

FROM node:6-slim WORKDIR /tmp

Install protractor and setup Headless Chrome browser

RUN npm install -g protractor &&
echo "deb http://ftp.debian.org/debian jessie-backports main" >> /etc/apt/sources.list &&
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - &&
sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' &&
wget -q -O - http://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - &&
echo 'deb http://dl.yarnpkg.com/debian/ stable main' | tee /etc/apt/sources.list.d/yarn.list &&
apt-get update &&
apt-get install -y libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4 &&
apt-get install -y google-chrome-stable &&
apt-get install -y xvfb gtk2-engines-pixbuf &&
apt-get install -y xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable &&
apt-get install -y imagemagick x11-apps dbus-x11 &&
apt-get install -y yarn

Install Java with webupd8 repository

RUN
echo "===> add webupd8 repository..." &&
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list &&
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list &&
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886 &&
apt-get update &&


echo "===> install Java" &&
echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections &&
echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections &&
DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes oracle-java8-installer oracle-java8-set-default &&


echo "===> clean up..." &&
rm -rf /var/cache/oracle-jdk8-installer &&
apt-get clean

Install Xvfb init script

ADD xvfb_init /etc/init.d/xvfb RUN chmod a+x /etc/init.d/xvfb

RUN apt-get install -y netcat RUN mkdir -p DIR WORKDIR /DIR ADD . ./ RUN yarn install

We use selenium-standalone rather than webdriver-manager,

since webdriver-manager can't work proper in China Region

RUN yarn global add selenium-standalone RUN selenium-standalone install

Fix for the issue with Selenium, as described here:

ENV DBUS_SESSION_BUS_ADDRESS=/dev/null ENV DISPLAY=:99 ENTRYPOINT ["./Filename"]

How to run ?

docker run -it --privileged --rm
--name containerName
-v /dev/shm:/dev/shm
imagename

Why mapping /dev/shm? Docker has hardcoded value of 64MB for /dev/shm. Because of that you can encounter an error session deleted becasue of page crash on memory intensive pages.

Up until Docker 1.10 the easiest way to mitigate that problem was to share /dev/shm with the host. Starting with Docker 1.10, we can use the option --shm-size to set the size of the shared memory to any arbitrary value. I recommend 2g, however you may want to experiment with this value.

For Mac OSX users this conversation can be useful.

$ hdiutil attach -nomount ram://$((2 * 1024 * SIZE_IN_MB)) /dev/disk3 $ diskutil eraseVolume HFS+ RAMDisk /dev/disk3

https://bugs.chromium.org/p/chromedriver/issues/detail?id=1097 https://unix.stackexchange.com/questions/151984/how-do-you-move-files-into-the-in-memory-file-system-mounted-at-dev-shm Why --privileged? Chrome uses sandboxing, therefore if you try and run Chrome within a non-privileged container you will receive the following message:

"Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted".

The --privileged flag gives the container almost the same privileges to the host machine resources as other processes running outside the container, which is required for the sandboxing to run smoothly.

SomeLinks : http://www.tothenew.com/blog/protractor-with-jenkins-and-headless-chrome-xvfb-setup/