【问题标题】:Chrome issues on Docker file with Jenkins and chromedriver使用 Jenkins 和 chromedriver 处理 Docker 文件的 Chrome 问题
【发布时间】:2019-09-19 19:45:43
【问题描述】:

您好,我正在自动测试我们的节点应用程序,为此我正在使用 jenkins。在我们进行浏览器测试时,我在本地机器上使用 jenkins、selenium、google chrome 和 chromedriver。

我想把它翻译成一个 docker 文件,我的 docker 文件看起来像这样。

# 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

这构建成功,当我将 docker 和 ssh 运行到正在运行的映像中并输入 google-chrome 时,我收到以下错误

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

跟踪/断点陷阱

当我在 Jenkins 中运行我的 npm 测试时,我收到以下错误,即 chrome 已崩溃

(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)

我的问题是:

我的 docker 文件有问题吗?

这里有什么我遗漏的吗?

【问题讨论】:

    标签: google-chrome jenkins selenium-chromedriver dockerfile


    【解决方案1】:

    在您的 Docker 示例中,您无权访问 X 服务器。所以我认为你需要在无头模式下运行 Chrome:

    /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
    

    另请参阅此问题:

    How to run google chrome headless in docker?

    【讨论】:

    • 所以我在我的 nodejs 测试 (.setChromeOptions(new chrome.Options().headless().windowSize(screen)) 中以无头模式运行 chrome,但它说 chrome 正在崩溃。
    • 您是否也尝试添加“--no-sandbox”?
    • 是的,我也添加了,我得到了与 chrome 崩溃相同的错误
    • 嗯。最好的方法是首先让 Chrome 从命令行运行而没有错误,然后尝试在 nodejs 测试中使用它。那么,当您运行 /usr/bin/goolgle-chrome --disable-gpu --headless --no-sandbox 时,您现在会遇到什么错误?您也可以尝试使用 docker run .... --privileged ..... 运行容器吗?
    • 我尝试运行它并得到了这个 - Fontconfig 警告:“/etc/fonts/fonts.conf”,第 100 行:未知元素“空白”
    猜你喜欢
    • 1970-01-01
    • 2015-02-21
    • 1970-01-01
    • 1970-01-01
    • 2018-01-03
    • 2011-10-11
    • 1970-01-01
    • 2018-11-10
    • 2018-06-05
    相关资源
    最近更新 更多