Skip to content

Commit ccc442e

Browse files
committed
[rb] expect responses to be wrapped in 'value' for w3c
1 parent 32a8970 commit ccc442e

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

rb/lib/selenium/webdriver/remote/response.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,20 @@ def add_backtrace(ex)
9595
ex.set_backtrace(backtrace + ex.backtrace)
9696
end
9797

98+
def error_payload
99+
# Even errors are wrapped in 'value' for w3c
100+
# Grab 'value' key for error, leave original payload alone and let the bridge process
101+
@error_payload ||= !@payload.key?('sessionId') ? @payload['value'] : @payload
102+
end
103+
98104
def status
99-
@payload['status'] || @payload['error']
105+
return unless error_payload.is_a? Hash
106+
@status ||= error_payload['status'] || error_payload['error']
100107
end
101108

102109
def value
103-
@payload['value'] || @payload['message']
110+
return unless error_payload.is_a? Hash
111+
@value ||= error_payload['value'] || error_payload['message']
104112
end
105113
end # Response
106114
end # Remote

rb/lib/selenium/webdriver/remote/w3c_bridge.rb

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def session_id
111111
end
112112

113113
def create_session(desired_capabilities)
114-
resp = raw_execute :new_session, {}, {desiredCapabilities: desired_capabilities}
114+
resp = execute :new_session, {}, {desiredCapabilities: desired_capabilities}
115115
@session_id = resp['sessionId']
116116
return W3CCapabilities.json_create resp['value'] if @session_id
117117

@@ -599,21 +599,10 @@ def convert_locators(how, what)
599599
# executes a command on the remote server.
600600
#
601601
#
602-
# Returns the 'value' of the returned payload
603-
#
604-
605-
def execute(*args)
606-
result = raw_execute(*args)
607-
result.payload.key?('value') ? result['value'] : result
608-
end
609-
610-
#
611-
# executes a command on the remote server.
612-
#
613602
# @return [WebDriver::Remote::Response]
614603
#
615604

616-
def raw_execute(command, opts = {}, command_hash = nil)
605+
def execute(command, opts = {}, command_hash = nil)
617606
verb, path = commands(command) || raise(ArgumentError, "unknown command: #{command.inspect}")
618607
path = path.dup
619608

@@ -628,7 +617,7 @@ def raw_execute(command, opts = {}, command_hash = nil)
628617
end
629618

630619
WebDriver.logger.info("-> #{verb.to_s.upcase} #{path}")
631-
http.call verb, path, command_hash
620+
http.call(verb, path, command_hash)['value']
632621
end
633622

634623
def escaper

0 commit comments

Comments
 (0)