I am trying to use the browserless/chrome docker image and connect to it from a Ruby on Rails (6.0) app running in another docker container. I'm having difficulty getting the two to connect.
The browserless container is running properly (I know because I can access the web debug interface it comes with).
In the Rails app, I am trying to use capybara with selenium-webdriver to drive a headless chrome instance.
I am getting errors saying that either it can't connect or that it cannot post to '/session', which I think means it's properly connecting but can't initialize a session within chrome for some reason.
Below is my current configuration + code:
#docker-compose.yml
version: "3"
services:
web:
build: .
image: sync-plus.web:latest
volumes:
- .:/app
ports:
- "3000:3000"
environment:
RAILS_ENV: development
RACK_ENV: development
REDIS_URL: redis://redis:6379/0
DATABASE_URL_TEST: postgres://postgres:super@postgres:5432/salesync_test
command: "bin/puma -C config/puma.rb"
depends_on:
- postgres
- mailcatcher
- redis
sidekiq:
image: sync-plus.web:latest
volumes:
- .:/app
environment:
RAILS_ENV: development
RACK_ENV: development
REDIS_URL: redis://redis:6379/0
DATABASE_URL_TEST: postgres://postgres:super@postgres:5432/salesync_test
command: "bundle exec sidekiq"
depends_on:
- postgres
- mailcatcher
- web
- redis
guard:
image: sync-plus.web:latest
volumes:
- .:/app
environment:
RAILS_ENV: test
RACK_ENV: test
REDIS_URL: redis://redis:6379/1
DATABASE_URL_TEST: postgres://postgres:super@postgres:5432/salesync_test
command: "bin/rspec"
depends_on:
- postgres
redis:
image: redis:alpine
command: redis-server
volumes:
- 'redis:/data'
postgres:
image: postgres:latest
volumes:
- postgres_volume:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: super
mailcatcher:
image: schickling/mailcatcher:latest
ports:
- "1080:1080"
browserless:
image: browserless/chrome:latest
ports:
- "4444:3000"
volumes:
postgres_volume:
redis:
#rails_helper.rb
...
require "rspec/rails"
# This require needs to be below the rspec/rails require
require 'capybara/rails'
...
I am using an Rspec test to check if the browserless connection/driving is functional:
#browserless_spec.rb
require "rails_helper"
RSpec.describe 'Browserless', type: :feature do
describe "Connection" do
it "can connect to browserless container" do
#selenium webdriver looks at localhost:4444 by default
driver = Selenium::WebDriver.for :remote
driver.visit("/users/sign_in")
expect(page).to have_selector("btn btn-outline-light my-2")
end
end
end
I can't seem to find any solid solutions or leads elsewhere, so any help would be much appreciated!
Thanks!