Skip to content

Instantly share code, notes, and snippets.

@wtnabe
Last active August 30, 2024 05:54
Show Gist options
  • Save wtnabe/bd0cf65bce3e94302f123f38567ec0d9 to your computer and use it in GitHub Desktop.
Save wtnabe/bd0cf65bce3e94302f123f38567ec0d9 to your computer and use it in GitHub Desktop.
PlaywrightをRSpec, Capybaraと組み合わせた時のhookに関係する挙動

RSpec hooks order

  • around
  • before
  • after
  • around

Capybara session

in capybara/rspec.rb

  config.after do
    if self.class.include?(Capybara::DSL)
      Capybara.reset_sessions!
      Capybara.use_default_driver
    end
  end
  
  config.before do |example|
    if self.class.include?(Capybara::DSL)
      Capybara.current_driver = Capybara.javascript_driver if example.metadata[:js]
      Capybara.current_driver = example.metadata[:driver] if example.metadata[:driver]
    end
  end

まとめ

Capybara の session から driver をたどって driver の機能を直接使うには after hook を抜ける前になんとかする必要がある。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment