selenium - 实现jenkins docker image + chrome + ruby​​未知错误时出现问题:Chrome无法启动:崩溃(Selenium::WebDriver::Error::UnknownError)

标签 selenium google-chrome docker jenkins selenium-chromedriver

我正在尝试使用官方的 Jenkins docker 镜像来设置 Jenkins 。

Docker文件

FROM jenkins/jenkins:lts

USER root
RUN apt-get update && apt install -y ruby-full
RUN apt-get install -y curl
RUN apt -y autoremove
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN apt-get install -y build-essential
RUN apt install -y wget
RUN gem install --no-ri --no-rdoc --format-executable rake
RUN gem install selenium-webdriver
RUN gem install bundler
RUN npm install -g node-mongo-seeds

#Permissions granted to jenkins user to do a gem install
RUN chown -R jenkins:jenkins /var/lib/gems
RUN apt-get install -y patch ruby-dev zlib1g-dev liblzma-dev
RUN chown -R jenkins:jenkins /usr/local/bin

# 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

# Set up the Chrome PPA
RUN wget -q -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 2.35
ENV CHROMEDRIVER_DIR /chromedriver
RUN mkdir $CHROMEDRIVER_DIR

# Download and install Chromedriver
RUN wget -q --continue -P $CHROMEDRIVER_DIR "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip"
RUN unzip $CHROMEDRIVER_DIR/chromedriver* -d $CHROMEDRIVER_DIR

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

USER jenkins

在运行作业时,浏览器将无法打开并进入本地主机。
我也尝试点击“google.com”
google-chrome --headless --no-sandbox 'https://www.google.com'

仍然没有成功
    Fontconfig warning: "/etc/fonts/fonts.conf", line 100: unknown element "blank"
[0531/130727.949511:ERROR:browser_process_sub_thread.cc(217)] Waited 17 ms for network service

我不明白为什么jenkins用户无法打开浏览器。
  • Google Chrome 74.0.3729.169
  • ChromeDriver 2.35.528139(47ead77cb35ad2a9a83248b292151462a66cd881)
  • ruby 2.3.3p222(2016-11-21)[x86_64-linux-gnu]
  • Jenkins 2.164.3
  • 最佳答案

    此错误消息...

    unknown error: Chrome failed to start: crashed (Selenium::WebDriver::Error::UnknownError)
    

    ...暗示 ChromeDriver 无法启动/产生新的 Web浏览器,即 Chrome浏览器 session 。

    您的主要问题是正在使用的二进制版本之间的不兼容,如下所示:
  • 您正在使用chromedriver = 2.35
  • chromedriver=2.35
  • 发行说明中明确提到以下内容:

  • Supports Chrome v62-64


  • 您正在使用chrome = 74.0
  • ChromeDriver v74.0
  • 发行说明中明确提到以下内容:

  • Supports Chrome v74



    因此,ChromeDriver v2.35和Chrome浏览器v74.0之间存在明显的不匹配


  • 将ChromeDriver升级到当前ChromeDriver v74.0级别。
  • 将Chrome版本保持在,Chrome v74 级别。 (as per ChromeDriver v2.46 release notes)
  • 通过IDE清洁项目工作区,并仅使用必需的依赖项重建项目。
  • 如果您的基本Web客户端版本太旧,则将其卸载并安装最新的GA和Web客户端发行版本。
  • 执行您的@Test
  • 关于selenium - 实现jenkins docker image + chrome + ruby​​未知错误时出现问题:Chrome无法启动:崩溃(Selenium::WebDriver::Error::UnknownError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56395728/

    相关文章:

    javascript - JavaScript 中元素的接口(interface)

    google-chrome - 如何使用网络音频 api 无缝循环声音

    postgresql - Adminer & Migrate 无法连接到 Postgresql Docker 容器

    docker - 在基于RHEL的Docker镜像上的SDK内部连接Docker守护程序

    python - 使用 py2exe 将 python selenium 脚本构建为 exe

    Python Selenium `move_by_offset` 不工作

    maven - 通过命令行使用 Maven 运行特定的 TestNG 套件

    java - Selenium WebDriver : unable to locate element inside iframe using TinyMCE editor

    javascript - 保持图像位置和正确的流动

    docker - 尝试在 Linux Ubuntu 18.04 Bionic 上安装 Docker CE 时显示错误?