0

Hi I am automating testing of our node applications and I am using jenkins for that. As we are doing browser testing, I am using jenkins, selenium, google chrome and chromedriver on my local machine.

I want to translate this into a docker file and my docker file look like this.

# Getting jenkins image
FROM jenkins/jenkins:2.176.3

# Changing the user to root
USER root
ENV TZ=America/New_York
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# installing chrome driver
RUN apt-get update && apt-get -qq -y install curl

RUN apt-get install ca-certificates

# We need wget to set up the PPA and xvfb to have a virtual screen and unzip to install the Chromedriver
RUN apt-get install -y wget xvfb unzip

RUN curl -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -

RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list

# Update the package list and install chrome
RUN apt-get update -y
RUN apt-get install -y google-chrome-stable


# Set up Chromedriver Environment variables
ENV CHROMEDRIVER_VERSION 76.0.3809.12
ENV CHROMEDRIVER_DIR /chromedriver
RUN mkdir $CHROMEDRIVER_DIR

RUN curl http://chromedriver.storage.googleapis.com/76.0.3809.12/chromedriver_linux64.zip -o /chromedriver/chromedriver_linux64.zip -J -L

RUN unzip $CHROMEDRIVER_DIR/chromedriver* -d $CHROMEDRIVER_DIR

RUN chmod 777 -R /chromedriver

# Put Chromedriver into the PATH
ENV PATH $CHROMEDRIVER_DIR:$PATH

USER jenkins

This builds successfully and when I run docker and ssh into the running image, and i type google-chrome I get the following error

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

Trace/breakpoint trap

When I run my npm tests in Jenkins I get the following error that chrome has crashed

(node:316) UnhandledPromiseRejectionWarning: WebDriverError: unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
at Object.throwDecodedError (node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:563:13)
at Executor.execute (node_modules/selenium-webdriver/lib/http.js:489:26)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:316) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

My question is:

Is there something that is wrong with my docker file?

Is there something that I am missing here?

Nikhil Das Nomula
  • 1,863
  • 5
  • 31
  • 50

1 Answers1

0

In your Docker example you don't have access to an X server. So I think you need to run Chrome in headless mode:

/usr/bin/google-chrome-unstable \
--disable-gpu --headless --no-sandbox \
--remote-debugging-address=0.0.0.0 \
--remote-debugging-port=9222 --user-data-dir=/data

Also see this issue:

How to run google chrome headless in docker?

dwjbosman
  • 906
  • 9
  • 33
  • So I am running chrome in headless mode in my nodejs tests (.setChromeOptions(new chrome.Options().headless().windowSize(screen)) , but its saying that chrome is crashing.. – Nikhil Das Nomula Sep 19 '19 at 20:10
  • Did you also try adding "--no-sandbox"? – dwjbosman Sep 19 '19 at 20:33
  • Yea I added that as well, I get the same error that chrome crashed – Nikhil Das Nomula Sep 19 '19 at 20:43
  • Hmm. Best approach would be to first get Chrome running from the command line without errors and then try to use it within nodejs tests. So what error do you get now when you run /usr/bin/goolgle-chrome --disable-gpu --headless --no-sandbox? Can you also try running the container with docker run .... --privileged .....? – dwjbosman Sep 19 '19 at 21:25
  • I tried running it and I get this - Fontconfig warning: "/etc/fonts/fonts.conf", line 100: unknown element "blank" – Nikhil Das Nomula Sep 20 '19 at 16:01