Skip to content

Commit

Permalink
[rb] explicitly handle all w3c required capabilities from session cre…
Browse files Browse the repository at this point in the history
…ation return value
  • Loading branch information
titusfortner committed Mar 1, 2021
1 parent 1d0ab3e commit 6e18624
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions rb/lib/selenium/webdriver/remote/capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,10 @@ def json_create(data)
data = data.dup

caps = new
caps.browser_name = data.delete('browserName') if data.key?('browserName')
caps.browser_version = data.delete('browserVersion') if data.key?('browserVersion')
caps.platform_name = data.delete('platformName') if data.key?('platformName')
caps.accept_insecure_certs = data.delete('acceptInsecureCerts') if data.key?('acceptInsecureCerts')
caps.page_load_strategy = data.delete('pageLoadStrategy') if data.key?('pageLoadStrategy')
(KNOWN - %i[timeouts proxy]).each do |cap|
data_value = camel_case(cap)
caps[cap] = data.delete(data_value) if data.key?(data_value)
end

process_timeouts(caps, data.delete('timeouts'))

Expand All @@ -142,14 +141,20 @@ def json_create(data)
end

# Remote Server Specific
caps[:remote_session_id] = data.delete('webdriver.remote.sessionid') if data.key?('webdriver.remote.sessionid')
if data.key?('webdriver.remote.sessionid')
caps[:remote_session_id] = data.delete('webdriver.remote.sessionid')
end

# any remaining pairs will be added as is, with no conversion
caps.merge!(data)

caps
end

def camel_case(str_or_sym)
str_or_sym.to_s.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
end

private

def process_timeouts(caps, timeouts)
Expand Down Expand Up @@ -232,7 +237,7 @@ def as_json(*)
when String
hash[key.to_s] = value
when Symbol
hash[camel_case(key.to_s)] = value
hash[self.class.camel_case(key)] = value
else
raise TypeError, "expected String or Symbol, got #{key.inspect}:#{key.class} / #{value.inspect}"
end
Expand All @@ -256,13 +261,6 @@ def ==(other)
protected

attr_reader :capabilities

private

def camel_case(str)
str.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
end

end # Capabilities
end # Remote
end # WebDriver
Expand Down

0 comments on commit 6e18624

Please sign in to comment.