8

TL;DR: Any idea about how to properly configure capybara to be able to drive a remote selenium browser in a docker container with default Rails minitest system test?

I'm running Rails in a dockerized env.. Now I want to start some "system tests" but since I'm running inside Docker I come up with some issues.

I'm using the default test suite (minitest?) with capybara and selenium-webdriver gems.

I've already installed the chromedriver packet in the container using the following:

RUN apt-get install -y chromedriver \
  && ln -s /usr/lib/chromium-browser/chromedriver /usr/local/bin

But running rails test:system outputs the following error Selenium::WebDriver::Error::WebDriverError: Unable to find chromedriver.

In fact I don't know if chrome itself is installed or not?
which chrome outputs nothing.
which chromium outputs /usr/bin/chromium.

I also tried with xvfb without success.

So (since I had no clue) I tried to go further and actually go with a dockerized system test environment as well.

I found some Docker images from selenium. So I ran among my rails and database containers a selenium-standalone-chrome container (the actual docker-compose.yml I'm using is here)

Then I found some useful information about the configuration to be done to let capybara driver the remote selenium browser.
All the examples I found on internet use rspec, but since I'm using the default minispec I tried to adapt the capybara driver to minispec but I had some doubt about how to do it and where to put the configuration.

For system tests I guessed that the best location is the file application_system_test_case.rb. Also I found and I tried many different capybara configurations and I end up with the following which seems to be the most complete (available here)

At that moment the test seems to perform well since I have no error but it always fails.

It fails regardless of making a call to the driver configuration (the setup_remote method where I defined the server host and port) before the tests case.

With or without the call I got the "site can't be reached" error (here is the screenshot)
Here is the test file I used. (Testing some react dynamic display)

However I can access to the selenium container with the given URL from the browser from my host machine. And both containers sees each others. I did some ping from within the containers shell.

The following SO questions being helpful don't work for me:
Dockerized selenium browser cannot access Capybara test url
How can I run headless browser system tests in Rails 5.1?

Any idea about how to properly configure capybara to be able to drive a remote selenium browser in a docker container with default Rails minitest system test?

Thank you very much.

SanjiBukai
  • 563
  • 5
  • 19
  • Hi again.. The default address of the remote selenium seems to be an address like `http://172.18.0.2:4444/wd/hub/`. But when I access this URL from the host using a browser it redirects to the following page `http://172.18.0.2:4444/wd/hub/static/resource/hub.html`. So I tried to put this URL in the register driver portion. This time I got some other selenium errors. But the most important thing is that among the console errros I also got some *"System Info"* which displays the same metadata displayed by the selenium site which means that the connection rails->selenium seems to work well. – SanjiBukai Jun 24 '17 at 04:26

1 Answers1

5

You have to override the host method so Capybara uses the container's IP address. Check out this post: https://medium.com/@pacuna/using-rails-5-1-system-tests-with-docker-a90c52ed0648

pacuna
  • 1,831
  • 16
  • 15
  • 1
    I pass from [this code](https://gist.github.com/sanjibukai/bfc5117221a006d4e6829e3e5a662388) to this [much simpler code](https://gist.github.com/sanjibukai/a3d9aa38e0b0ae05368a7999fb813b4b), thank you.. – SanjiBukai Jun 27 '17 at 09:07