Skip to content

Commit

Permalink
system testing: disable chrome's search engine choice modal
Browse files Browse the repository at this point in the history
starting chrome with a fresh profile shows a search engine choice screen
which will break any tests. passing a special argument will disable the
screen.

see SeleniumHQ/selenium#14431

also:
- refactor default chrome option initialization
- compress browser option initialization
  • Loading branch information
glaszig authored and garrettblehm committed Sep 9, 2024
1 parent 67a0042 commit 0daef54
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* System Testing: Disable Chrome's search engine choice by default in system tests.

*glaszig*

* Fix `Request#raw_post` raising `NoMethodError` when `rack.input` is `nil`.

*Hartley McGuire*
Expand Down
33 changes: 12 additions & 21 deletions actionpack/lib/action_dispatch/system_testing/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Browser # :nodoc:

def initialize(name)
@name = name
set_default_options
end

def type
Expand All @@ -27,9 +26,9 @@ def options
@options ||=
case type
when :chrome
::Selenium::WebDriver::Chrome::Options.new
default_chrome_options
when :firefox
::Selenium::WebDriver::Firefox::Options.new
default_firefox_options
end
end

Expand All @@ -49,26 +48,18 @@ def preload
end

private
def set_default_options
case name
when :headless_chrome
set_headless_chrome_browser_options
when :headless_firefox
set_headless_firefox_browser_options
end
def default_chrome_options
options = ::Selenium::WebDriver::Chrome::Options.new
options.add_argument("--disable-search-engine-choice-screen")
options.add_argument("--headless") if name == :headless_chrome
options.add_argument("--disable-gpu") if Gem.win_platform?
options
end

def set_headless_chrome_browser_options
configure do |capabilities|
capabilities.add_argument("--headless")
capabilities.add_argument("--disable-gpu") if Gem.win_platform?
end
end

def set_headless_firefox_browser_options
configure do |capabilities|
capabilities.add_argument("-headless")
end
def default_firefox_options
options = ::Selenium::WebDriver::Firefox::Options.new
options.add_argument("-headless") if name == :headless_firefox
options
end

def resolve_driver_path(namespace)
Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/dispatch/system_testing/driver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class DriverTest < ActiveSupport::TestCase

expected = {
"goog:chromeOptions" => {
"args" => ["start-maximized"],
"args" => ["--disable-search-engine-choice-screen", "start-maximized"],
"mobileEmulation" => { "deviceName" => "iphone 6" },
"prefs" => { "detach" => true }
},
Expand All @@ -101,7 +101,7 @@ class DriverTest < ActiveSupport::TestCase

expected = {
"goog:chromeOptions" => {
"args" => ["--headless", "start-maximized"],
"args" => ["--disable-search-engine-choice-screen", "--headless", "start-maximized"],
"mobileEmulation" => { "deviceName" => "iphone 6" },
"prefs" => { "detach" => true }
},
Expand Down

0 comments on commit 0daef54

Please sign in to comment.