diff --git a/rb/lib/selenium/webdriver/common/options.rb b/rb/lib/selenium/webdriver/common/options.rb index bddb91063737b..997aced69ec5d 100644 --- a/rb/lib/selenium/webdriver/common/options.rb +++ b/rb/lib/selenium/webdriver/common/options.rb @@ -131,11 +131,20 @@ def w3c?(key) def process_w3c_options(options) w3c_options = options.select { |key, val| w3c?(key) && !val.nil? } - w3c_options[:unhandled_prompt_behavior] &&= w3c_options[:unhandled_prompt_behavior]&.to_s&.tr('_', ' ') + w3c_options[:unhandled_prompt_behavior] &&= + process_unhandled_prompt_behavior_value(w3c_options[:unhandled_prompt_behavior]) options.delete_if { |key, _val| w3c?(key) } w3c_options end + def process_unhandled_prompt_behavior_value(value) + if value.is_a?(Hash) + value.transform_values { |v| process_unhandled_prompt_behavior_value(v) } + else + value&.to_s&.tr('_', ' ') + end + end + def process_browser_options(_browser_options) nil end diff --git a/rb/spec/unit/selenium/webdriver/chrome/options_spec.rb b/rb/spec/unit/selenium/webdriver/chrome/options_spec.rb index 5061aae7cc7ec..96a739ea9611b 100644 --- a/rb/spec/unit/selenium/webdriver/chrome/options_spec.rb +++ b/rb/spec/unit/selenium/webdriver/chrome/options_spec.rb @@ -267,6 +267,26 @@ module Chrome {'args' => ["--user-data-dir=#{directory}"]}) end + it 'processes unhandled_prompt_behavior hash values' do + opts = described_class.new(unhandled_prompt_behavior: { + alert: :accept_and_notify, + confirm: 'dismiss_and_notify', + prompt: :ignore, + before_unload: 'accept', + default: :dismiss + }) + + expect(opts.as_json).to eq('browserName' => 'chrome', + 'unhandledPromptBehavior' => { + 'alert' => 'accept and notify', + 'confirm' => 'dismiss and notify', + 'prompt' => 'ignore', + 'beforeUnload' => 'accept', + 'default' => 'dismiss' + }, + 'goog:chromeOptions' => {}) + end + it 'returns a JSON hash' do allow(File).to receive(:file?).and_return(true) allow_any_instance_of(described_class)