実現したいこと
feturespecにおいてajaxを用いたいいね機能をテストしたい
発生している問題 エラ〜メッセージ
Failures: 1) Likes like_button Failure/Error: visit new_user_session_path Selenium::WebDriver::Error::WebDriverError: Unable to find chromedriver. Please download the server from https://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH. More info at https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. # /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/common/service.rb:136:in `binary_path' # /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/common/service.rb:94:in `initialize' # /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/common/service.rb:41:in `new' # /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/common/service.rb:41:in `chrome' # /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/common/driver.rb:299:in `service_url' # /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/chrome/driver.rb:40:in `initialize' # /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/common/driver.rb:46:in `new' # /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/common/driver.rb:46:in `for' # /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver.rb:88:in `for' # /usr/local/bundle/gems/capybara-3.35.3/lib/capybara/selenium/driver.rb:83:in `browser' # /usr/local/bundle/gems/capybara-3.35.3/lib/capybara/selenium/driver.rb:104:in `visit' # /usr/local/bundle/gems/capybara-3.35.3/lib/capybara/session.rb:278:in `visit' # /usr/local/bundle/gems/capybara-3.35.3/lib/capybara/dsl.rb:53:in `call' # /usr/local/bundle/gems/capybara-3.35.3/lib/capybara/dsl.rb:53:in `visit' # ./spec/support/login_macros.rb:3:in `log_in' # ./spec/features/like_spec.rb:8:in `block (2 levels) in <top (required)>' Finished in 1.63 seconds (files took 11.02 seconds to load) 1 example, 1 failure Failed examples: rspec ./spec/features/like_spec.rb:11 # Likes like_button ERROR: 1
該当コード
require 'rails_helper' RSpec.feature 'Likes', type: :feature do let(:user) { FactoryBot.create(:user)} before do create(:micropost) log_in(user) end scenario 'like_button', js: true do visit microposts_path click_link '詳細' find('.far').click expect(page).to have_css '.fas' end end
log_in(user)はspec/support/login_macros.rbに書いてあります
module LoginMacros def log_in(user) visit new_user_session_path fill_in 'user_email', with: user.email fill_in 'user_password', with: user.password click_button I18n.t('.devise.sessions.new.sign_in') end
試したこと
以下のエラーが出ており、Docker環境内にchromeが入っていないと考え,
docker-compose.rmlやcapybara.rbにselenium_chromeに関する記述をしました。
すると最初のエラーが発生しました。
Webdrivers::BrowserNotFound: Failed to find Chrome binary.
補足情報
開発環境
Dockerfile
FROM ruby:2.7.1 RUN apt-get update -qq && apt-get install -y nodejs postgresql-client RUN apt-get update && apt-get install -y curl apt-transport-https wget && \ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ apt-get update && apt-get install -y yarn # Node.jsをインストール RUN curl -sL https://deb.nodesource.com/setup_7.x | bash - && \ apt-get install nodejs RUN mkdir /myapp WORKDIR /myapp COPY Gemfile /myapp/Gemfile COPY Gemfile.lock /myapp/Gemfile.lock RUN bundle install COPY . /myapp # Add a script to be executed every time the container starts. COPY entrypoint.sh /usr/bin/ RUN chmod +x /usr/bin/entrypoint.sh ENTRYPOINT ["entrypoint.sh"] EXPOSE 3000 # Start the main process. CMD ["rails", "server", "-b", "0.0.0.0"]
docker-compose.yml
version: '3' services: db: image: postgres volumes: - ./tmp/db:/var/lib/postgresql/data #######追加######################### environment: POSTGRES_HOST_AUTH_METHOD: 'trust' ################################### web: build: . command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" volumes: - .:/myapp ports: - "3000:3000" depends_on: - db environment: - "SELENIUM_DRIVER_URL=http://selenium_chrome:4444/wd/hub" selenium_chrome: image: selenium/standalone-chrome-debug logging: driver: none
spec/support/capybara.rb
Capybara.register_driver :chrome_headless do |app| options = ::Selenium::WebDriver::Chrome::Options.new options.add_argument('--headless') options.add_argument('--no-sandbox') options.add_argument('--disable-dev-shm-usage') options.add_argument('--window-size=1400,1400') Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) end Capybara.javascript_driver = :selenium_chrome_headless RSpec.configure do |config| config.before(:each, type: :system) do driven_by :rack_test end config.before(:each, type: :system, js: true) do if ENV["SELENIUM_DRIVER_URL"].present? driven_by :selenium, using: :chrome, options: { browser: :remote, url: ENV.fetch("SELENIUM_DRIVER_URL"), desired_capabilities: :chrome } else driven_by :selenium_chrome_headless end end end
あなたの回答
tips
プレビュー