[RAILS] Unable to connect to chromedriver error when running SystemSpec

# Introduction

When I run SystemSpec, the following error occurs. Leave the resolved procedure.

environment

windows10 Home ruby 2.7.0 Rails 6.0.3.4 ubuntu 18.04


     1.1) Failure/Error: visit new_user_session_path

          Selenium::WebDriver::Error::WebDriverError:
            unable to connect to chromedriver 127.0.0.1:9515
          # ./spec/system/users_spec.rb:9:in `block (2 levels) in <main>'

     1.2) Failure/Error: raise Error::WebDriverError, cannot_connect_error_text

          Selenium::WebDriver::Error::WebDriverError:
            unable to connect to chromedriver 127.0.0.1:9515

# What I tried

Install Google chrome in terminal

Check if chromeDriver is installed by referring to the article below, and install it because it was not installed.
Install Chrome on Ubuntu

#Make sure it is not installed
apt list --installed google*


#google.Add to last line of list
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'


#Confirm that it has been registered
ls -l /etc/apt/sources.list.d
>-rw-r--r-- 1 root root  55 Jan 21 09:45 google.list

cat /etc/apt/sources.list.d/google.list
>deb http://dl.google.com/linux/chrome/deb/ stable main


#Download the public key and apt the public key-Register with key
sudo wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -


#Update package list
sudo apt update


#Installation
sudo apt-get install google-chrome-stable


Another error occurred

capybara-webkit was not installed so install it

     1.1) Failure/Error: visit new_user_session_path

          Selenium::WebDriver::Error::UnknownError:
            unknown error: Chrome failed to start: exited abnormally.
              (unknown error: DevToolsActivePort file doesn't exist)
              (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
          # #0 0x5595e5ed6199 <unknown>
          # ./spec/system/users_spec.rb:9:in `block (2 levels) in <main>'

     1.2) Failure/Error: Unable to infer file and line number from backtrace

          Selenium::WebDriver::Error::UnknownError:
            unknown error: Chrome failed to start: exited abnormally.
              (unknown error: DevToolsActivePort file doesn't exist)
              (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
          # #0 0x555be43fb199 <unknown>

Add capybara-webkit to Gemfile and bundle install

Gemfile


  gem 'capybara-webkit'

#### Error when installing capybara-webkit
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/wayne/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/capybara-webkit-1.15.1
/home/wayne/.rbenv/versions/2.7.0/bin/ruby -I /home/wayne/.rbenv/versions/2.7.0/lib/ruby/2.7.0 -r
./siteconf20210121-14230-122xkh.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/wayne/.rbenv/versions/2.7.0/bin/$(RUBY_BASE_NAME)
        --with-gl-dir
        --without-gl-dir
        --with-gl-include
        --without-gl-include=${gl-dir}/include
        --with-gl-lib
        --without-gl-lib=${gl-dir}/lib
        --with-zlib-dir
        --without-zlib-dir
        --with-zlib-include
        --without-zlib-include=${zlib-dir}/include
        --with-zlib-lib
        --without-zlib-lib=${zlib-dir}/lib
Command 'qmake ' not available

Refer to the official website https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit
sudo apt-get update
sudo apt-get install g++ qt5-default libqt5webkit5-dev gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-x

Run bundle install


Same error as before

     1.1) Failure/Error: visit new_user_session_path

          Selenium::WebDriver::Error::UnknownError:
            unknown error: Chrome failed to start: exited abnormally.
              (unknown error: DevToolsActivePort file doesn't exist)
              (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
          # #0 0x5653be207199 <unknown>
          # ./spec/system/users_spec.rb:9:in `block (2 levels) in <main>'

     1.2) Failure/Error: Unable to infer file and line number from backtrace

          Selenium::WebDriver::Error::UnknownError:
            unknown error: Chrome failed to start: exited abnormally.
              (unknown error: DevToolsActivePort file doesn't exist)
              (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
          # #0 0x559795ddb199 <unknown>

Refer to the article below [Rspec settings only need to be written in rails_helper.rb](https://qiita.com/kazutosato/items/8255a685206b327ad151)

rails_helper.rb


  #use headless chrome with system spec
  config.before(:each) do |example|
    if example.metadata[:type] == :system
      driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
    end
  end

Run rspec

Finished in 1.22 seconds (files took 0.7511 seconds to load)
14 examples, 0 failures

I passed!

Recommended Posts

Unable to connect to chromedriver error when running SystemSpec
Error when trying to use heroku command
ERROR 2002 (HY000) when starting MySQL: Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2)
Solution that gives an error when trying to connect to DB (MySQL) in Java
[Grails] Error occurred running What to do when the Grails CLI does not start
Error when running git push heroku master on Heroku
Java compilation error Unable to map to encoding windows-31j
Error in bundle install when running rails new
When deploying to Heroku, OpenApp causes an error
Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2) error
What to do when a null byte error occurs
Error ExecJS :: RuntimeUnavailable: What to do when it occurs