Dockerizedselenium浏览器不能访问Capybaratestingurl

我正在尝试在dockerized selenium独立的firefox浏览器上运行Ruby on Railsfunctiontesting。 这似乎是我有networking问题,因为selenium实例无法连接到由水豚开始的url。

这里是我的示例docker-compose.yml文件:

 ff: image: selenium/standalone-firefox:2.48.2 container_name: firefox-browser web: build: . container_name: my-app volumes: - ".:/home/ubuntu/my-app" command: /bin/bash -l scripts/docker-start-tests.sh ports: - "3000:3000" 

我开始docker-compose与networking启用:

 docker-compose --x-networking up 

testing脚本像这样运行一个rspec命令

 rspec ./spec/features/login_spec.rb:43 

dockertesting我启用了远程驱动程序水豚:

 Capybara.register_driver :docker_firefox do |app| Capybara::Selenium::Driver.new(app, { browser: :remote, url: "#{ENV['FF_URL']}/wd/hub", desired_capabilities: Selenium::WebDriver::Remote::Capabilities.firefox }) end 

最后,我打电话给这样的testing:

 unless ENV['FF_URL'].nil? Capybara.current_driver = :docker_firefox Capybara.javascript_driver = :docker_firefox Capybara.app_host = "http://my-app:56555" Capybara.server_port = "56555" # Capybara.server_host = "my-app" end visit root_path save_and_open_screenshot click_link "Sign in" ... 

我可以尾巴浏览器容器日志,我看到selenium收到来自水豚的命令。 问题是它无法连接到提供的url,我可以用截图来确认。

Firefox无法在my-app:56555build立到服务器的连接

为了更好地理解问题,我开始了rails应用程序,并试图从selenium容器访问它。 我注意到,我只能从selenium容器访问应用程序,如果我启动与ip绑定的rails应用程序。

 rails s Puma -b 0.0.0.0 

这看起来像一个networking问题,但我找不出解决scheme。

我如何使selenium容器访问轨道应用程序运行与水豚Rspecfunctiontesting?

 capybara (2.6.0) selenium-webdriver (2.48.1) 

谢谢你的帮助。

服务器线程轨道运行testing应用程序绑定到Capybara.server_host接口(默认为127.0.0.1) – 您可以将其更改为任何IP接口泊坞窗容器可以对您的机器 – 可能的情况下

 Capybara.server_host = '0.0.0.0' # bind to all interfaces