Skip to content

Commit 0157c8f

Browse files
committed
[rb] fix parsing differences between options and capabilities
1 parent 26e46fb commit 0157c8f

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

rb/lib/selenium/webdriver/common/options.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ def ==(other)
109109
def as_json(*)
110110
options = @options.dup
111111

112-
w3c_options = options.select { |key, _val| W3C_OPTIONS.include?(key) }
113-
options.delete_if { |key, _val| W3C_OPTIONS.include?(key) }
112+
w3c_options = process_w3c_options(options)
114113

115114
self.class::CAPABILITIES.each do |capability_alias, capability_name|
116115
capability_value = options.delete(capability_alias)
@@ -124,6 +123,13 @@ def as_json(*)
124123

125124
private
126125

126+
def process_w3c_options(options)
127+
w3c_options = options.select { |key, _val| W3C_OPTIONS.include?(key) }
128+
w3c_options[:unhandled_prompt_behavior] &&= w3c_options[:unhandled_prompt_behavior]&.to_s&.tr('_', ' ')
129+
options.delete_if { |key, _val| W3C_OPTIONS.include?(key) }
130+
w3c_options
131+
end
132+
127133
def process_browser_options(_browser_options)
128134
nil
129135
end

rb/lib/selenium/webdriver/common/proxy.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ def type=(type)
141141

142142
def as_json(*)
143143
json_result = {
144-
'proxyType' => TYPES[type],
144+
'proxyType' => TYPES[type].downcase,
145145
'ftpProxy' => ftp,
146146
'httpProxy' => http,
147-
'noProxy' => no_proxy,
147+
'noProxy' => no_proxy.is_a?(String) ? no_proxy.split(', ') : no_proxy,
148148
'proxyAutoconfigUrl' => pac,
149149
'sslProxy' => ssl,
150150
'autodetect' => auto_detect,

rb/lib/selenium/webdriver/remote/capabilities.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,23 +307,13 @@ def convert_value(key, value)
307307
when :platform
308308
value.to_s.upcase
309309
when :proxy
310-
convert_proxy(value)
310+
value&.as_json
311311
when :unhandled_prompt_behavior
312312
value.is_a?(Symbol) ? value.to_s.tr('_', ' ') : value
313313
else
314314
value
315315
end
316316
end
317-
318-
def convert_proxy(value)
319-
return unless value
320-
321-
hash = value.as_json
322-
hash['proxyType'] &&= hash['proxyType'].downcase
323-
hash['noProxy'] = hash['noProxy'].split(', ') if hash['noProxy'].is_a?(String)
324-
325-
hash
326-
end
327317
end # Capabilities
328318
end # Remote
329319
end # WebDriver

rb/spec/unit/selenium/webdriver/chrome/options_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ module Chrome
235235
opts = Options.new(browser_version: '75',
236236
platform_name: 'win10',
237237
accept_insecure_certs: false,
238-
page_load_strategy: 'eager',
239-
unhandled_prompt_behavior: 'accept',
238+
page_load_strategy: :eager,
239+
unhandled_prompt_behavior: :accept_and_notify,
240240
strict_file_interactability: true,
241241
timeouts: {script: 40000,
242242
page_load: 400000,
@@ -268,7 +268,7 @@ module Chrome
268268
'platformName' => 'win10',
269269
'acceptInsecureCerts' => false,
270270
'pageLoadStrategy' => 'eager',
271-
'unhandledPromptBehavior' => 'accept',
271+
'unhandledPromptBehavior' => 'accept and notify',
272272
'strictFileInteractability' => true,
273273
'timeouts' => {'script' => 40000,
274274
'pageLoad' => 400000,

rb/spec/unit/selenium/webdriver/proxy_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ module WebDriver
7070
it 'should return a hash of the json properties to serialize', :aggregate_failures do
7171
proxy_json = Proxy.new(proxy_settings).as_json
7272

73-
expect(proxy_json['proxyType']).to eq('MANUAL')
73+
expect(proxy_json['proxyType']).to eq('manual')
7474
expect(proxy_json['ftpProxy']).to eq(proxy_settings[:ftp])
7575
expect(proxy_json['httpProxy']).to eq(proxy_settings[:http])
76-
expect(proxy_json['noProxy']).to eq(proxy_settings[:no_proxy])
76+
expect(proxy_json['noProxy']).to eq([proxy_settings[:no_proxy]])
7777
expect(proxy_json['sslProxy']).to eq(proxy_settings[:ssl])
7878
expect(proxy_json['socksProxy']).to eq(proxy_settings[:socks])
7979
expect(proxy_json['socksUsername']).to eq(proxy_settings[:socks_username])
@@ -84,14 +84,14 @@ module WebDriver
8484
it 'should configure a PAC proxy', :aggregate_failures do
8585
proxy_json = Proxy.new(pac_proxy_settings).as_json
8686

87-
expect(proxy_json['proxyType']).to eq('PAC')
87+
expect(proxy_json['proxyType']).to eq('pac')
8888
expect(proxy_json['proxyAutoconfigUrl']).to eq(pac_proxy_settings[:pac])
8989
end
9090

9191
it 'should configure an auto-detected proxy', :aggregate_failures do
9292
proxy_json = Proxy.new(auto_detect: true).as_json
9393

94-
expect(proxy_json['proxyType']).to eq('AUTODETECT')
94+
expect(proxy_json['proxyType']).to eq('autodetect')
9595
expect(proxy_json['autodetect']).to be true
9696
end
9797

@@ -101,7 +101,7 @@ module WebDriver
101101
proxy = Proxy.new(settings)
102102
proxy_json = proxy.as_json
103103

104-
expect(proxy_json.delete('proxyType')).to eq(settings[:type].to_s.upcase)
104+
expect(proxy_json.delete('proxyType')).to eq(settings[:type].to_s)
105105
expect(proxy_json.delete('httpProxy')).to eq(settings[:http])
106106

107107
expect(proxy_json).to be_empty

0 commit comments

Comments
 (0)