@@ -115,6 +115,50 @@ def reposition_window(x, y, handle = :current)
115115 def maximize_window ( handle = :current )
116116 execute :maximize_window , window_handle : handle
117117 end
118+
119+ def create_session ( desired_capabilities )
120+ resp = raw_execute :new_session , { } , { desiredCapabilities : desired_capabilities }
121+ @session_id = resp [ 'sessionId' ]
122+ return Remote ::W3CCapabilities . json_create resp [ 'value' ] if @session_id
123+
124+ raise Error ::WebDriverError , 'no sessionId in returned payload'
125+ end
126+
127+ #
128+ # executes a command on the remote server.
129+ #
130+ #
131+ # Returns the 'value' of the returned payload
132+ #
133+
134+ def execute ( *args )
135+ result = raw_execute ( *args )
136+ result . payload . key? ( 'value' ) ? result [ 'value' ] : result
137+ end
138+
139+ #
140+ # executes a command on the remote server.
141+ #
142+ # @return [WebDriver::Remote::Response]
143+ #
144+
145+ def raw_execute ( command , opts = { } , command_hash = nil )
146+ verb , path = commands ( command ) || raise ( ArgumentError , "unknown command: #{ command . inspect } " )
147+ path = path . dup
148+
149+ path [ ':session_id' ] = @session_id if path . include? ( ':session_id' )
150+
151+ begin
152+ opts . each do |key , value |
153+ path [ key . inspect ] = escaper . escape ( value . to_s )
154+ end
155+ rescue IndexError
156+ raise ArgumentError , "#{ opts . inspect } invalid for #{ command . inspect } "
157+ end
158+
159+ WebDriver . logger . info ( "-> #{ verb . to_s . upcase } #{ path } " )
160+ http . call verb , path , command_hash
161+ end
118162 end # Bridge
119163 end # Edge
120164 end # WebDriver
0 commit comments