Webdrivers :: BrowserNotFound: Failed to find Chrome binary. When I was trying to test E2E with Docker + Rails for the first time, I got stuck in an error.

I'll leave it as a memorandum that there was something like this because it was packed a lot.

First article I referred to https://qiita.com/at-946/items/e96eaf3f91a39d180eb3

I tried to implement it referring to the above article, but I get an error without a browser. why. .. ..

Failure/Error: driven_by :remote_chrome 
Webdrivers::BrowserNotFound: Failed to find Chrome binary. 

When I checked various things, the normal test passed, but when I tried to test javascript (js: true), it seems to be moss with the above error.

  config.before(:each, type: :system, js: true) do
    driven_by :remote_chrome
    Capybara.server_host = IPSocket.getaddress(Socket.gethostname)
    Capybara.server_port = 3000
    Capybara.app_host = "http://#{Capybara.server_host}:#{Capybara.server_port}"
  end

↑ So this part of the article I referred to is not working well ...?

Check the chrome container

Try accessing http: // localhost: 4444 / wd / hub. image.png

It seems that it is moving properly as if looking at the display.

Check if communication is reaching the chrome container from the web container

Launch a shell on the web container

$ docker-compose run --rm web sh

Check if communication is possible

$ ping chrome
64 bytes from ... 

Confirm that the letters are flowing all the time. Apparently the web container and chrome container are connected properly. I don't understand more and more. .. ..

No matter what you add or delete with reference to various other articles

Failure/Error: driven_by :〇〇〇
Webdrivers::BrowserNotFound: Failed to find Chrome binary. 

Suffering from the error.

By the way, the Dockerfile looks like this.

Dockerfile


FROM ruby:2.6.6-alpine3.11
RUN apk --no-cache add tzdata \
                       libxml2-dev \
                       curl-dev \
                       make \
                       gcc \
                       libc-dev \
                       g++ \
                       bash \
                       mariadb-dev \
                       mariadb-client \
                       yarn \
                       sqlite-dev

RUN gem install bundler -v "2.0.2"

RUN mkdir /myapp
WORKDIR /myapp

COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install

COPY . /myapp

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]

EXPOSE 3000
CMD ["bundle", "exec", "falcon", "--verbose", "serve", "-p", "3000", "-b", "http://0.0.0.0"]

Think from the beginning

I got stuck with copy and paste and couldn't go anymore, so I went back to the beginning.

What do I need when doing a browser (E2E) test?

-Web browser Chrome, Firefox, IE, Opera, etc.

  • WebDriver Module that exposes the API for operating the browser
  • Selenium A library that communicates with WebDriver and operates the browser programmatically

(Quoted from here https://qiita.com/Chanmoro/items/9a3c86bb465c1cce738a)

You will need these three when testing your browser. In the environment with Docker, the above is not available, so you need to prepare all of them.

Also, about how to prepare a browser --Build chrome with the same image as the rails environment --Add container for chrome to docker-compose --Launch the chrome container with the docker command There are various methods such as.

① Try it with the new rails new app

The article I referred to first, https://qiita.com/at-946/items/e96eaf3f91a39d180eb3, didn't work. .. ..

② Try to refer to another article

https://qiita.com/ngron/items/f61b8635b4d67f666d75#comments Next, I will refer to this article. Then it worked with the rails new app! A little forward!

However, I got an error in the app that originally wanted to implement the test code. Here is the error at that time.

/bin/sh: apt-get: not found

If you look up the error text, this article is a hit. https://qiita.com/HorikawaTokiya/items/a2a174680d7dd759ccae

Alpine Linux? ?? ?? ?? Ubuntu? ?? ?? Why the OS story ...?

③ Think about the difference between the existing app and the app created with rails new

Was there something where the OS was set ...? While thinking, try to find a different description between the rails new app and the existing app.

Dockerfile


FROM ruby:2.6.6

Dockerfile (existing app)


FROM ruby:2.6.6-alpine3.11

Ah! I'm writing Alpine! But what do you mean ...? ?? ?? Since I was aware of what is necessary to create a container for docker image, suddenly the story of OS came out and there is a description of OS in ruby image? ?? It is in a state.

The following was taught by an engineer (thank you ...)

Alpine uses APK as a package manager, Debian and Ubuntu use APT. A package manager is like a place that provides tools and apps that can be installed on the OS, such as the iPhone App Store and Android Play Store. Package managers are divided by OS (or rather a faction), and the installed apps are slightly different for each. Also, the same app, such as MySQL, is called mysql-server for APT, and mysql for APK, which is also slightly different.

In the case of Docker, the reason why the OS is different depends on the image you are using.

For example, Ruby image https://hub.docker.com/_/ruby

There are> 2.5.8 to 3.0.0, but the OS name (or OS code name) is alpine or slim after each.

APT and APK should be considered as applications, and APT and APK are different applications, so they are used differently.

④ Try changing the ruby image to ubuntu's

I didn't have any reason to use alpine, so I rewrote the existing app ruby to ubuntu. Then, if you proceed according to this article https://qiita.com/ngron/items/f61b8635b4d67f666d75#comments earlier, the js test will pass even with the existing application! It was long. .. ..

Conclusion

After all, I didn't understand why it didn't work in the first article I referred to. However, the article that did not work was how to add a container for chrome to docker-compose, and the article that worked was how to build chrome with the same image as the rails environment, so the former was for some reason such as a version difference. Wasn't the web container and chrome container linked? (It is a mystery that ping chrome passed ...)

I tried various articles this time and learned that there are differences in the OS in the image.

Recommended Posts

Webdrivers :: BrowserNotFound: Failed to find Chrome binary. When I was trying to test E2E with Docker + Rails for the first time, I got stuck in an error.
[Error resolution] Occurs when trying to build an environment for spring with docker
When I bcrypt with node + docker, I got an error
I was angry with proc_open (): fork failed when trying to composer update inside a Docker container
I got an IllegalAccessError when trying to use PowerMock with JUnit
[Ruby on Rails] When logging in for the first time ・ How to split the screen in half using jQuery
When I tried to build an environment of PHP7.4 + Apache + MySQL with Docker, I got stuck [Windows & Mac]
Problems I was addicted to when building the digdag environment with docker
I want to display an error message when registering in the database
I was stuck with the handling of the time zone when formatting with SimpleDateFormat
In WSL2, when I did `docker-compose up`, I got an error saying that the sh file was not found.
I tried using Docker for the first time
What to do when ‘Could not find’ in any of the sources appears in the development environment with Docker × Rails × RSpec
I tried touching Docker for the first time
I got an "ActionView :: Template :: Error: Permission denied" error in the test of 3.3.1 of Rails tutorial 6th edition, so I solved it.
How to deal with the error yaml.scanner.ScannerError: while scanning for the next token that appeared in Rails environment construction with Docker
A story that got stuck with an error during migration in docker PHP laravel
I got an error when trying to install sbt to build a Scala development environment
What I was addicted to when trying to properly openAPI/Swagger documentation with Rails + Grape + Grape Swagger
[Docker] When I did docker-compose build, I got an error saying Can not read file. .. [Rails 6.0]
After posting an article with Rails Simple Calendar, I want to reflect it in the calendar.
When trying to insert a specific gem (levenshtein) with Docker, an error occurred without ruby-dev
I was addicted to WSl when trying to build an android application development environment with Vue.js
The story when the test folder was not created in Rails
[Rails] I tried using the button_to method for the first time
Technical causes and countermeasures for the points I was addicted to with the first Android app & Kotlin
[Programming beginner] What to do when rails s becomes an error in the local development environment