skip to Main Content

I’m installing chrome driver from the docker file. Base image is ruby.

Here’s my docker file:

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:

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:

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. Locally everything is running fine.

2

Answers


  1. Chosen as BEST ANSWER

    The error I was getting was because of the test. I changed the rails test, and the error got resolved.

    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:

    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
    

  2. 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.

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search