Selenium Docked Browser Cannot Access Capybara Test URL

I am trying to run Ruby on Rails feature tests on a standalone Firefox browser. It seems that I'm having network problems because the selenium instance cannot connect to the URL started by Capybara.

Here is my docker-compose.yml file example:

 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" 

And I start connecting dockers with network support enabled:

 docker-compose --x-networking up 

The test script runs an rspec command similar to this

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

For docker tests, I enabled the remote driver for Capybara:

 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 

And finally, I call the test as follows:

 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" ... 

I can display browser container logs and I see that selenium is receiving commands from Capybara. The problem is that it cannot connect to the provided url, which I can confirm with a screenshot.

Firefox cannot establish server connection in my-app: 56555

To better understand the problem, I ran the rails application and I tried to access it from the selenium container. I notice that I can only access the application from the selenium container if I run the rails application with ip binding.

 rails s Puma -b 0.0.0.0 

This seems like a network problem, but I cannot find a solution.

How can I make a selenium container access a rails application using Rspec function tests with Capybara?

 capybara (2.6.0) selenium-webdriver (2.48.1) 

Thank you for your help.

+5
source share
1 answer

The server thread rails run the test application in bindings to the Capybara.server_host interface (default is 127.0.0.1). You can change this to any ip interface that the docker container can talk on your computer - in your case, maybe

 Capybara.server_host = '0.0.0.0' # bind to all interfaces 
+4
source

Source: https://habr.com/ru/post/1241799/


All Articles