ruby-on-rails - 连接 Rails 应用程序和无浏览器/chrome 容器
问题描述
我正在尝试使用browserless/chrome
docker 映像并从在另一个 docker 容器中运行的 Ruby on Rails (6.0) 应用程序连接到它。我很难让两者联系起来。
无浏览器容器运行正常(我知道是因为我可以访问它附带的 Web 调试界面)。
在 Rails 应用程序中,我尝试使用capybara
withselenium-webdriver
来驱动无头 chrome 实例。
我收到错误消息说它无法连接或无法发布到“/会话”,我认为这意味着它正在正确连接但由于某种原因无法在 chrome 中初始化会话。
以下是我当前的配置+代码:
#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'
...
我正在使用 Rspec 测试来检查无浏览器连接/驱动是否正常工作:
#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
我似乎在其他地方找不到任何可靠的解决方案或线索,所以任何帮助将不胜感激!
谢谢!
解决方案
推荐阅读
- command - 为什么当我执行 Pascal 程序时,控制台中的部分信息会被删除?
- angular - Angular rxjs:多个依赖的休息调用,第一次完成时显示
- excel - Unable to Reference Pivot Table Sufficiently in Excel
- java - 从 Java 中的 Mule ObjectStore 中检索存储
- netlogo - 有没有解决方案只有观察者可以询问Netlogo中所有海龟的集合?
- amazon-kinesis - Kinesis 分片读取限制为 2 mib,那么获取记录调用怎么可能达到 10mib
- gojs - GoJs addDiagramListener SelectionMoved 使用 SelectedNode 获取数据
- c++ - ostream_iterator operator= 在对上失败
,但适用于包装类。我不能为pair<>重载operator<<吗? - python - 在 Python 中,“类型注释”和“类型提示”是一回事吗?
- keras - 检查目标时出错:预期 dense_34 有 2 个维度,但得到的数组形状为 (64, 10, 2)