Follow-up question, now I’m on RSpec 3.9.3 with Ruby 2.4.10 and Rails 5.1.7, and it seems that the correct solution for getting headless chrome includes the following in the RSpec configuration (instead of the Capybara #register_driver calls):
RSpec.configure do |config| config.before(:each, type: :system, js: true) do driven_by :selenium_chrome_headless end end What I’m wondering is why “driven_by” is only supported on “system” specs and not on “feature” specs. Feature specs with “js: true” will always run the full Chrome version, as it stands now (I’ve checked rspec-rails and determined that #driven_by is defined in RSpec::Rails::SystemExampleGroup). Or is that something that will change if I upgrade one or more gems? My understanding is that the only difference between the two modes is whether or not a browser display appears, so if you can do all the same things in a feature spec as a system spec, why can’t you go headless with a feature spec? > On Dec 1, 2020, at 11:50 AM, Jack Royal-Gordon <jac...@pobox.com> wrote: > > When I tried that, I got a “NoMethodError”. The example was a feature, not a > system spec, and #driven_by is only defined for system tests. So I made it a > system test, and then I got the following error: > > LoadError: cannot load such file -- action_dispatch/system_test_case System > test integration requires Rails >= 5.1 and has a hard dependency on a > webserver and `capybara`, please add capybara to your Gemfile and configure a > webserver (e.g. `Capybara.server = :webrick`) before attempting to use system > specs. > > I’m on 5.0 (haven’t finished testing with 5.0 so not ready to migrate to > 5.1). The message leads me to believe that headless Chrome will only work on > Rails >= 5.1 (which makes sense, since the articles on headless chrome > started showing up about two months after 5.1 was released). > >> On Dec 1, 2020, at 7:35 AM, Phil Pirozhkov <pirjs...@gmail.com >> <mailto:pirjs...@gmail.com>> wrote: >> >> Jack, >> >> Do you mean that it opens the Chrome application window? >> I recall we were making some changes to prevent Rails from overriding the >> default drivers. >> >> Off the top of my head you can try setting the driver in a `before` hook >> https://relishapp.com/rspec/rspec-rails/v/4-0/docs/system-specs/system-spec#system-specs-driven-by-selenium-chrome-headless >> >> <https://relishapp.com/rspec/rspec-rails/v/4-0/docs/system-specs/system-spec#system-specs-driven-by-selenium-chrome-headless> >> >> >> On Tue, Dec 1, 2020 at 3:25 AM Jack Royal-Gordon <jac...@pobox.com >> <mailto:jac...@pobox.com>> wrote: >> I know that this is not specifically an RSpec issue, but the Capybara user >> forum is unresponsive and appears relatively inactive, and the RSpec group >> has been very responsive and informative on topics beyond the strict scope >> of RSpec. I’m trying to implement headless Chrome with Capybara and Selenium >> for RSpec feature tests, and I followed the instructions in the following >> article: >> https://www.imaginarycloud.com/blog/from-capybara-webkit-to-headless-chrome-and-chromedriver/ >> >> <https://www.imaginarycloud.com/blog/from-capybara-webkit-to-headless-chrome-and-chromedriver/> >> >> I’ve added the following gems: webdrivers (v 3.9.4), capybara-selenium (v >> 0.0.6), and capybara (v 3.15.1). In my spec_helper.rb file, I’ve added the >> following code: >> >> Capybara.register_driver :chrome do |app| >> Capybara::Selenium::Driver.new(app, browser: :chrome) >> end >> >> Capybara.register_driver :headless_chrome do |app| >> capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( >> chromeOptions: { >> args: %w[headless >> enable-features=NetworkService,NetworkServiceInProcess] >> } >> ) >> >> Capybara::Selenium::Driver.new app, >> browser: :chrome, >> desired_capabilities: capabilities >> end >> >> Capybara.default_driver = :headless_chrome >> Capybara.javascript_driver = :headless_chrome >> >> What I’m getting, when I run a feature spec with js:true is a full browser, >> which is obviously not what I’m expecting. Is there anything obvious that >> I’m doing wrong here? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "rspec" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rspec+unsubscr...@googlegroups.com >> <mailto:rspec+unsubscr...@googlegroups.com>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/rspec/828B0D8D-B280-4A3E-B416-F78658A5A754%40pobox.com >> >> <https://groups.google.com/d/msgid/rspec/828B0D8D-B280-4A3E-B416-F78658A5A754%40pobox.com?utm_medium=email&utm_source=footer>. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "rspec" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rspec+unsubscr...@googlegroups.com >> <mailto:rspec+unsubscr...@googlegroups.com>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/rspec/CAAk5Ok-QqqdVrQmxSL7waPs1RFtvA-BfyseGT4kQTDAtkBZLoQ%40mail.gmail.com >> >> <https://groups.google.com/d/msgid/rspec/CAAk5Ok-QqqdVrQmxSL7waPs1RFtvA-BfyseGT4kQTDAtkBZLoQ%40mail.gmail.com?utm_medium=email&utm_source=footer>. > > > -- > You received this message because you are subscribed to the Google Groups > "rspec" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rspec+unsubscr...@googlegroups.com > <mailto:rspec+unsubscr...@googlegroups.com>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/rspec/C15243D3-6C54-4FA0-B7FE-DCB80B6E8FF0%40pobox.com > > <https://groups.google.com/d/msgid/rspec/C15243D3-6C54-4FA0-B7FE-DCB80B6E8FF0%40pobox.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/3C601915-A872-4533-B4ED-1244A45D8FF2%40pobox.com.