as far as I know driven_by is part of the Rails DSL for system specs, not RSpec feature specs. I've never had to use it with feature specs
Actually I've never used Rails new system specs, I've always used RSpec/Capybara feature specs with both headless & non headless drivers for years, they work great Here's how I configure headless chrome with capybara ## Headless! Capybara.register_driver :headless_chrome do |app| options = Selenium::WebDriver::Chrome::Options.new options.add_argument('--headless') options.add_argument('--disable-gpu') options.add_argument('--test-type') options.add_argument('--ignore-certificate-errors') options.add_argument('--disable-popup-blocking') options.add_argument('--disable-extensions') options.add_argument('--enable-automation') options.add_argument('--window-size=1920,1080') options.add_argument("--start-maximized") capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( logging_prefs: { 'browser' => 'ALL' } ) Capybara::Selenium::Driver.new app, browser: :chrome, options: options, desired_capabilities: capabilities end ## Capy Configuration Defaults Capybara.configure do |config| config.server = :puma config.javascript_driver = (ENV['HEADLESS'] || ENV['H']) ? :headless_chrome : :chrome config.default_max_wait_time = 7 end I use an environment variable to control when I pick headless or not from the command line, i.e. H=1 bundle exec rspec spec/models/ feature specs go in a /features directory under my /spec directory and look like the following, note the :js tag to trigger the browser vs the capybara default :rack_test (no browser) RSpec.feature 'Admin can do stuff, :js do describe 'fancy feature' do it 'works well' do # spec implementation end end end On Wednesday, December 2, 2020 at 11:16:09 AM UTC-7 Jack R-G wrote: > 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 <pirj...@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 > > > On Tue, Dec 1, 2020 at 3:25 AM Jack Royal-Gordon <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/ >> >> 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+un...@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+un...@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+un...@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/a51e1cc9-fddb-4b6b-a1f2-9e0ac0c19a2en%40googlegroups.com.