rubycdp / ferrum

Headless Chrome Ruby API
https://ferrum.rubycdp.com
MIT License
1.69k stars 120 forks source link

Ferrum::BinaryNotFoundError when using docker for chrome #390

Closed floydj closed 6 months ago

floydj commented 11 months ago

This is a Rails 7.1 alpha app, running Cuprite for system testing. I've seen several issues here and on Cuprite's repo that come close to this, but not that dealt with this exact error. It kinda seems like Cuprite/Ferrum isn't reading the application_system_test_case.rb file?

Every system test fails with:

Ferrum::BinaryNotFoundError: Could not find an executable for the browser. Try to make it available on the PATH or set environment variable for example BROWSER_PATH="/usr/bin/chrome"

All system tests work fine if I run all of this locally, without Docker. I have verified using curl from inside the test container that the http://chrome:3333 URL is working fine.

I've been working on this for parts of three days, but I'm officially out of ideas. How can I work past this?

Here's my docker-compose.yml:

version: "3.8"

x-base: &base
  build:
    context: .
    dockerfile: Dockerfile.dev
  stdin_open: true
  tty: true

services:
  app:
    <<: *base
    command: bin/dev
    volumes:
      - .:/app:cached
    ports:
      - "3000:3000"
    depends_on:
      - postgres
    environment:
      DATABASE_URL: postgres://postgres:example@postgres
      RUBY_YJIT_ENABLE: 1

  postgres:
    image: postgres:latest
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: example

  chrome:
    image: browserless/chrome:latest
    ports:
      - 3333:3333
    volumes:
      - .:/app:cached
    environment:
      PORT: 3333
      CONNECTION_TIMEOUT: 600000

  test:
    <<: *base
    volumes:
      - .:/app:cached
    environment:
      DATABASE_URL: postgres://postgres:example@postgres
    depends_on:
      - chrome
      - postgres

volumes:
  postgres_data:

My test/application_system_test_case.rb:

require "capybara/cuprite"
require "test_helper"

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  Capybara.register_driver(:cuprite) do |app|
    Capybara::Cuprite::Driver.new(app, window_size: [1200, 1000],
                                       browser_options: { 'no-sandbox': nil },
                                       url: "http://chrome:3333")
  end

  Capybara.javascript_driver = :cuprite

  # have tried these options w/o success:
  # Capybara.run_server = false
  # Capybara.app_host = "http://chrome:3333"
  # Capybara.always_include_port = true

  driven_by :cuprite
end

And finally, Dockerfile.dev:

FROM ruby:3.2.2

ENV RAILS_ENV=development

RUN apt update -qq && \
  apt install -y --no-install-recommends build-essential libpq-dev postgresql-client curl && \
  curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg -o /root/yarn-pubkey.gpg && \
  apt-key add /root/yarn-pubkey.gpg && \
  echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list && \
  apt update && \
  apt install -y --no-install-recommends nodejs yarn && \
  apt clean && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY Gemfile* ./
RUN bundle install -j $(nproc)

COPY package.json yarn.lock ./
RUN yarn install --ignore-scripts

CMD ["rails", "server", "-b", "0.0.0.0"]
route commented 6 months ago

I’m pretty sure evil martians use similar setup and all works https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing

This might be your issue https://github.com/rubycdp/cuprite/issues/180#issuecomment-1778037596