【问题标题】:Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: exited abnormallySelenium::WebDriver::Error::UnknownError: 未知错误: Chrome 启动失败: 异常退出
【发布时间】:2021-05-03 04:45:14
【问题描述】:

我正在从 docker 文件安装 chrome 驱动程序。基本图像是 ruby​​。

这是我的 docker 文件:

FROM ruby:2.7.2

# install packages
RUN apt-get update && apt-get install -y \
  curl \
  build-essential \
  libpq-dev &&\
  curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
  curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
  echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
  apt-get update && apt-get install -y nodejs yarn

# 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

ENV CHROME_BIN=/usr/bin/google-chrome

# Install bundler
RUN gem install bundler 
RUN bundle config path /usr/local/bundle

# Make work directory
RUN mkdir -p /myapp/gatherer
WORKDIR /myapp/gatherer

# copy gem files
COPY ./app/Gemfile /myapp/Gemfile
COPY ./app/Gemfile.lock /myapp/Gemfile.lock


# Install bundle
RUN gem update bundler
RUN bundle check || bundle install 

# copy .json and .lock files
COPY ./app/package.json /myapp/package.json
COPY ./app/yarn.lock /myapp/yarn.lock

# COPY all files
COPY ./app /myapp

#install yarn
RUN yarn install

但是在使用bundle exec rspec 运行测试后,我得到了这个错误:

1.3) Failure/Error: Unable to infer file and line number from backtrace
          
          Selenium::WebDriver::Error::UnknownError:
            unknown error: Chrome failed to start: exited abnormally.
              (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.)

这是我配置 chrome 的方式:

browsers: ['ChromeHeadlessNoSandbox'],
    customLaunchers: {
      ChromeHeadlessNoSandbox: {
        base: 'ChromeHeadless',
        flags: ['--headless', '--disable-gpu','--no-sandbox','--disable-dev-shm-usage']
      }
    },

如何解决此错误?当我在本地运行代码时,我没有收到此错误,只是在 docker-image 中出现错误。本地一切运行良好。

【问题讨论】:

    标签: ruby-on-rails docker selenium-chromedriver dockerfile google-chrome-devtools


    【解决方案1】:

    您似乎需要添加更多 Chrome 功能,但正如您将在以下主题中看到的那样 - 有不同的解决方案可以解决此错误,其中一种可能适用于您。

    WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser

    【讨论】:

      【解决方案2】:

      我得到的错误是因为测试。我更改了rails测试,错误得到了解决。

      导致我出错的测试:

        it "can re-order a task", :js do
          visit(project_path(project))
          find("#task_3")
          within("#task_3") do
            click_on("Up")
          end
          expect(page).to have_selector("tbody:nth-child(2) .name", text: "Take Notes")
            #END:P1
            #START:P2
          visit(project_path(project))
          find("#task_2")
          within("#task_2") do
            expect(page).to have_selector(".name", text: "Use Telescope")
          end
        end
      

      删除:js后,错误得到解决:

      it "can re-order a task" do
          visit(project_path(project))
          find("#task_3")
          within("#task_3") do
            click_on("Up")
          end
          expect(page).to have_selector("tbody:nth-child(2) .name", text: "Take Notes")
            #END:P1
            #START:P2
          visit(project_path(project))
          find("#task_2")
          within("#task_2") do
            expect(page).to have_selector(".name", text: "Use Telescope")
          end
        end
      

      【讨论】:

      • 这行得通,但我确实需要 js 来满足某些规格!
      • 这只是一种解决方法,如果您的规范确实需要 JS,问题仍然存在
      猜你喜欢
      • 2015-08-14
      • 2017-06-17
      • 2018-02-13
      • 2023-01-07
      • 1970-01-01
      • 2014-04-20
      • 1970-01-01
      • 2019-10-17
      • 1970-01-01
      相关资源
      最近更新 更多