简体   繁体   English

Selenium::WebDriver::Error::UnknownError: 未知错误: Chrome 启动失败: 异常退出

[英]Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: exited abnormally

I'm installing chrome driver from the docker file.我正在从 docker 文件安装 chrome 驱动程序。 Base image is ruby.基本图像是 ruby。

Here's my docker file:这是我的 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

But after running the test using bundle exec rspec I get this error:但是在使用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.)

Here's how I'm configuring the chrome:这是我配置 chrome 的方式:

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

How can I resolve this error?我该如何解决这个错误? When I run the code locally I'm not getting this error, only getting error in docker-image.当我在本地运行代码时,我没有收到此错误,仅在 docker-image 中收到错误。 Locally everything is running fine.在本地一切都运行良好。

Looks like you need to add more Chrome capabilities, but as you will see in the below topic - there are different solutions for solving this error, one of them might apply to you.看起来您需要添加更多 Chrome 功能,但正如您将在下面的主题中看到的那样 - 有多种解决此错误的解决方案,其中一种可能适用于您。

WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser WebDriverException:未知错误:尝试启动 Chrome 浏览器时 DevToolsActivePort 文件不存在

The error I was getting was because of the test.我得到的错误是因为测试。 I changed the rails test, and the error got resolved.我更改了 rails 测试,错误得到解决。

The test because of which I was getting an error:因为我得到一个错误的测试:

  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

After removing :js , error got resolved:删除: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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Net :: ReadTimeout:Net :: ReadTimeout和Selenium :: WebDriver :: Error :: UnknownError:未知错误:Chrome无法启动Rails 5.1.beta系统测试 - Net::ReadTimeout: Net::ReadTimeout and Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start on Rails 5.1.beta System Test 如何在Amazon Linux上使用带有chrome驱动程序的selenium。 错误:Selenium :: WebDriver :: Error :: UnknownError:未知错误:找不到Chrome二进制文件 - How to use selenium with chrome driver on Amazon Linux. error: Selenium::WebDriver::Error::UnknownError: unknown error: cannot find Chrome binary Docker-compose 测试 Selenium 失败 / Selenium::WebDriver::Error::UnknownError: unknown error:.net::ERR_CONNECTION_REFUSED - Docker-compose testing with Selenium fails / Selenium::WebDriver::Error::UnknownError: unknown error: net::ERR_CONNECTION_REFUSED Selenium::WebDriver::Error::UnknownError: 无效的内容类型 - Selenium::WebDriver::Error::UnknownError: Invalid Content-Type 如何修复 WSL2 中的“Selenium::WebDriver::Error::WebDriverError: chrome notreachable” - How to fix "Selenium::WebDriver::Error::WebDriverError: chrome not reachable" in WSL2 Selenium 不适用于 Heroku (Selenium::WebDriver::Error::SessionNotCreatedError) - Selenium not working on Heroku (Selenium::WebDriver::Error::SessionNotCreatedError) Webrat Selenium:无法启动新的浏览器会话:启动浏览器时出错(Selenium :: CommandError) - Webrat Selenium: Failed to start new browser session: Error while launching browser (Selenium::CommandError) 红宝石cron硒webdriver错误 - ruby cron selenium-webdriver error 黄瓜/水豚/ Selenium-Webdriver错误? - Cucumber/Capybara/Selenium-Webdriver error? Ruby无法捕获Selenium :: WebDriver :: Error :: StaleElementReferenceError - Ruby unable to catch Selenium::WebDriver::Error::StaleElementReferenceError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM