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 ...?
Try accessing http: // localhost: 4444 / wd / hub
.
It seems that it is moving properly as if looking at the display.
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"]
I got stuck with copy and paste and couldn't go anymore, so I went back to the beginning.
-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.
The article I referred to first, https://qiita.com/at-946/items/e96eaf3f91a39d180eb3
, didn't work. .. ..
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 ...?
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.
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. .. ..
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