Skip to content

Commit 616abc1

Browse files
authored
Merge pull request #935 from amatsuda/revise_capybara_config
Revise Capybara config for stable system specs
2 parents 4a6ba10 + b764d9f commit 616abc1

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

spec/rails_helper.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@
8888
FactoryBot.reload
8989
end
9090

91-
config.after(:each, js: true) do |example|
92-
if example.exception
93-
screenshot_path = Rails.root.join("tmp/screenshots", "#{method_name}-#{Time.zone.now.strftime("%Y_%m_%d-%H_%M_%S")}.png")
94-
Capybara.page.save_screenshot(screenshot_path)
95-
end
96-
end
97-
9891
config.around(:each, caching: true) do |example|
9992
Rails.configuration.action_controller.perform_caching = true
10093
example.run
@@ -105,8 +98,23 @@
10598
driven_by :rack_test
10699
end
107100

101+
Capybara.register_driver :headless_chrome do |app|
102+
options = Selenium::WebDriver::Chrome::Options.new
103+
options.add_argument('--headless=new')
104+
options.add_argument('--disable-gpu')
105+
options.add_argument('--no-sandbox')
106+
options.add_argument('--disable-dev-shm-usage')
107+
options.add_argument('--window-size=1400,1400')
108+
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
109+
end
110+
108111
config.before type: :system, js: true do
109-
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
112+
driven_by :headless_chrome
113+
end
114+
115+
config.after type: :system, js: true do
116+
# Force a fresh browser session for each test to prevent state bleeding
117+
Capybara.send(:session_pool).delete_if { |k, _v| k.include?('headless_chrome') }
110118
end
111119

112120
Capybara.disable_animation = true

0 commit comments

Comments
 (0)