teamcapybara / capybara

Acceptance test framework for web applications

Home Page:http://teamcapybara.github.io/capybara/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Capybara Chrome resets developer tools between tests

rbclark opened this issue · comments

Meta

Capybara Version: 3.40.0

Driver Information (and browser if relevant): selenium-webdriver (4.18.1), Chrome (122)

Expected Behavior

I have created a custom Capybara driver that I use for debugging. The definition looks as follows:

Capybara.register_driver :chrome_with_network_tab do |app|
  options = Selenium::WebDriver::Chrome::Options.new(args: %w[auto-open-devtools-for-tabs])
  options.add_preference(
    "devtools",
    "preferences" => {
      "currentDockState" => '"right"',
      "panel-selectedTab" => '"network"'
    }
  )

  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    options: options
  )
end

When running this I expect that every test will be run with the devtools open to the network tab.

Actual Behavior

Instead of running every test with the devtools open, it only runs the first test in the series with devtools open. It is then closed for any subsequent tests. I've found that removing the following 2 lines from the Chrome driver has caused the devtools to be maintained between tests, which has at least helped me in the short term:

switch_to_window(window_handles.first)
window_handles.slice(1..).each { |win| close_window(win) }

Steps to reproduce

This can be reproduced by dropping this Capybara driver into any project that utilizes system tests.

This is a niche edge case, Capybara intentionally closes extra windows opened during the test -- if you don't want that behavior feel free to monkeypatch the reset! method in your use case