Docker + Rspec + Cuprite / receiving a blank page

424 views Asked by At

I have a (Rails 5.2, Ruby 2.5.8) working app configured with docker and I'm having problems running my system tests with Rspec and Cuprite.

I've followed this guide to set everything up, but when I run the test suite, all system specs fail.

I tried running simple tests, like visiting a page and checking a text existence, but they are always red. I check the screenshots generated by running the tests, and the only thing I see is a blank page. I see the same thing when I debug it with cuprite, using page.driver.pause.

I added a binding.pry in the controller action and it doesn't seem to get to that point.

This is the error I see:

Failure/Error: expect(page).to have_text('Foo')
       expected to find text "Foo" in ""

This is my configuration:

docker-compose.yml

  rspec_system:
    build: .
    tty: true
    stdin_open: true
    depends_on:
      - db
      - chrome
    volumes:
      - .:/usr/src/app:cached
      - bundler:/usr/local/bundle:delegated
      - bootsnap_cache:/usr/src/bootsnap:delegated
      - rails_cache:/usr/src/app/tmp/cache:delegated
    environment:
      - DATABASE_URL=postgres://postgres:postgres@db:5432/
      - CHROME_URL=http://chrome:3333
    ports:
      - '3000:3000'

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

spec/support/cuprite_setup.rb

REMOTE_CHROME_URL = ENV["CHROME_URL"]
REMOTE_CHROME_HOST, REMOTE_CHROME_PORT =
  if REMOTE_CHROME_URL
    URI.parse(REMOTE_CHROME_URL).yield_self do |uri|
      [uri.host, uri.port]
    end
  end

# Check whether the remote chrome is running and configure the Capybara
# driver for it.
remote_chrome =
  begin
    if REMOTE_CHROME_URL.nil?
      false
    else
      Socket.tcp(REMOTE_CHROME_HOST, REMOTE_CHROME_PORT, connect_timeout: 1).close
      true
    end
  rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError
    false
  end

remote_options = remote_chrome ? {url: REMOTE_CHROME_URL} : {}

require "capybara/cuprite"

Capybara.register_driver(:better_cuprite) do |app|
  Capybara::Cuprite::Driver.new(
    app,
    **{
      window_size: [2560, 1440],
      browser_options: remote_chrome ? {"no-sandbox" => nil} : {},
      inspector: true
    }.merge(remote_options)
  )
end

Capybara.default_driver = Capybara.javascript_driver = :better_cuprite
  config.prepend_before(:each, type: :system) do
    driven_by Capybara.javascript_driver
  end
Capybara.server_host = "0.0.0.0"
Capybara.app_host = "http://#{ENV.fetch("APP_HOST", `hostname`.strip&.downcase || "0.0.0.0")}"
0

There are 0 answers