So without any good reason my Rails 7.2 RSpec system test that run on headless Chrome Selenium Webdriver started to fail on error
<code>RSpec::Core::MultipleExceptionError: no such window
(Session info: chrome=127.0.6533.88)
invalid argument: 'handle' must be a string
(Session info: chrome=127.0.6533.88)
</code>
<code>RSpec::Core::MultipleExceptionError: no such window
(Session info: chrome=127.0.6533.88)
invalid argument: 'handle' must be a string
(Session info: chrome=127.0.6533.88)
</code>
RSpec::Core::MultipleExceptionError: no such window
(Session info: chrome=127.0.6533.88)
invalid argument: 'handle' must be a string
(Session info: chrome=127.0.6533.88)
Full error:
No code change no config change
<code>Capybara.register_driver :chrome_headless do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
options.add_argument("--headless=new") unless ENV["GUI"] == "on"
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--window-size=1400,1400")
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
</code>
<code>Capybara.register_driver :chrome_headless do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
options.add_argument("--headless=new") unless ENV["GUI"] == "on"
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--window-size=1400,1400")
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
</code>
Capybara.register_driver :chrome_headless do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
options.add_argument("--headless=new") unless ENV["GUI"] == "on"
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--window-size=1400,1400")
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
Turns out this was due to an update of my Chrome on my OSx. The main change was that this update contained “Select Your Search Engine” prompt:
and that will cause webdriver to switch context to different screen
solution is to turn off this prompt with
<code>Capybara.register_driver :chrome_headless do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
# ...
options.add_argument("--disable-search-engine-choice-screen")
</code>
<code>Capybara.register_driver :chrome_headless do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
# ...
options.add_argument("--disable-search-engine-choice-screen")
</code>
Capybara.register_driver :chrome_headless do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
# ...
options.add_argument("--disable-search-engine-choice-screen")
works !