26
26
import org .openqa .selenium .firefox .ExtensionConnection ;
27
27
import org .openqa .selenium .firefox .FirefoxBinary ;
28
28
import org .openqa .selenium .firefox .FirefoxProfile ;
29
- import org .openqa .selenium .firefox .NotConnectedException ;
30
29
import org .openqa .selenium .internal .Lock ;
31
30
import org .openqa .selenium .logging .LocalLogs ;
32
31
import org .openqa .selenium .logging .NeedsLocalLogs ;
47
46
import java .io .Reader ;
48
47
import java .net .ConnectException ;
49
48
import java .net .Socket ;
50
- import java .net .URL ;
51
- import java .util .Arrays ;
52
49
import java .util .List ;
53
50
import java .util .Map ;
54
51
@@ -64,7 +61,7 @@ public class MarionetteConnection implements ExtensionConnection, NeedsLocalLogs
64
61
private File profileDir ;
65
62
66
63
private static Map <String , String > seleniumToMarionetteCommandMap = ImmutableMap .<String , String >builder ()
67
- .put (DriverCommand .GET , "goUrl " )
64
+ .put (DriverCommand .GET , "get " )
68
65
.put (DriverCommand .GET_CURRENT_WINDOW_HANDLE , "getWindow" )
69
66
.put (DriverCommand .GET_WINDOW_HANDLES , "getWindows" )
70
67
.put (DriverCommand .CLOSE , "closeWindow" )
@@ -162,6 +159,7 @@ public void start() throws IOException {
162
159
// This initializes the "actor" for future communication with this instance.
163
160
sendCommand (serializeCommand (new Command (null , "getMarionetteID" )));
164
161
String getMarionetteIdRawResponse = receiveResponse ();
162
+ System .out .println (getMarionetteIdRawResponse );
165
163
Map <String , Object > map = new JsonToBeanConverter ().convert (Map .class ,
166
164
getMarionetteIdRawResponse );
167
165
marionetteId = map .get ("id" ).toString ();
@@ -191,14 +189,8 @@ public Response execute(Command command) throws IOException {
191
189
Map <String , Object > map = new JsonToBeanConverter ().convert (Map .class , rawResponse );
192
190
Response response ;
193
191
if (DriverCommand .NEW_SESSION .equals (command .getName ())) {
194
- // If we're starting a new session, we need to return the response
195
- // with that session.
196
- // ***************************************************************
197
- // Marionette Compliance Issue: The response should return the
198
- // newly created session ID in the "sessionId" member of the
199
- // returned JSON object.
200
- // ***************************************************************
201
- response = new Response (new SessionId (map .get ("value" ).toString ()));
192
+ // See https://bugzilla.mozilla.org/show_bug.cgi?id=1073732
193
+ response = new Response (new SessionId (new BeanToJsonConverter ().convert (map .get ("value" ))));
202
194
response .setValue (Maps .newHashMap ());
203
195
204
196
} else {
@@ -217,17 +209,27 @@ public Response execute(Command command) throws IOException {
217
209
// }
218
210
// ***************************************************************
219
211
response = new Response ();
220
- Map <String , Object > errorMap = (Map <String , Object >) map .get ("error" );
221
- if (errorMap != null ) {
222
- response .setStatus (Integer .parseInt (errorMap .get ("status" ).toString ()));
223
- errorMap .remove ("status" );
224
- response .setValue (errorMap );
212
+ Object value = map .get ("error" );
213
+ if (value != null ) {
214
+ if (value instanceof Map ) {
215
+ Map <String , Object > errorMap = (Map <String , Object >) value ;
216
+ if (errorMap != null ) {
217
+ response .setStatus (Integer .parseInt (errorMap .get ("status" ).toString ()));
218
+ errorMap .remove ("status" );
219
+ response .setValue (errorMap );
220
+ }
221
+ } else {
222
+ response .setStatus (ErrorCodes .UNHANDLED_ERROR );
223
+ response .setValue (value + ": " + map .get ("message" ));
224
+ }
225
225
}
226
226
227
227
} else {
228
+ response = new JsonToBeanConverter ().convert (Response .class , rawResponse );
229
+
228
230
// ***************************************************************
229
- // Marionette Compliance Issue: Responses from findElement and
230
- // findElements are returned with raw element IDs as the value.
231
+ // Marionette Compliance Issue: Responses from findElements
232
+ // are returned with raw element IDs as the value.
231
233
// This should be a JSON object with the following structure:
232
234
//
233
235
// { "ELEMENT": "<element ID goes here>" }
@@ -236,11 +238,7 @@ public Response execute(Command command) throws IOException {
236
238
// a raw string and an element reference returned from the
237
239
// executeScript command.
238
240
// ***************************************************************
239
- response = new JsonToBeanConverter ().convert (Response .class , rawResponse );
240
-
241
- if (DriverCommand .FIND_ELEMENT .equals (command .getName ())
242
- || DriverCommand .FIND_CHILD_ELEMENT .equals (command .getName ())
243
- || DriverCommand .GET_ACTIVE_ELEMENT .equals (command .getName ()))
241
+ if (DriverCommand .GET_ACTIVE_ELEMENT .equals (command .getName ()))
244
242
{
245
243
if (response .getStatus () == ErrorCodes .SUCCESS ) {
246
244
Map <String , Object > wrappedElement = Maps .newHashMap ();
@@ -278,51 +276,17 @@ private String serializeCommand(Command command) {
278
276
if (DriverCommand .NEW_SESSION .equals (commandName )) {
279
277
params .remove ("desiredCapabilities" );
280
278
281
- } else if (DriverCommand .GET .equals (commandName )) {
282
- renameParameter (params , "url" , "value" );
283
-
284
279
} else if (DriverCommand .SET_TIMEOUT .equals (commandName )) {
285
280
String timeoutType = (String ) params .get ("type" );
286
- // System.out.println("timeout type = " + timeoutType);
287
281
if ("implicit" .equals (timeoutType )) {
288
282
commandName = "setSearchTimeout" ;
289
283
} else if ("script" .equals (timeoutType )) {
290
284
commandName = "setScriptTimeout" ;
291
285
}
292
286
params .remove ("type" );
293
- renameParameter (params , "ms" , "value" );
294
-
295
- } else if (DriverCommand .EXECUTE_SCRIPT .equals (commandName )
296
- || DriverCommand .EXECUTE_ASYNC_SCRIPT .equals (commandName )) {
297
- renameParameter (params , "script" , "value" );
298
-
299
- } else if (DriverCommand .SWITCH_TO_WINDOW .equals (commandName )) {
300
- renameParameter (params , "name" , "value" );
301
-
302
- } else if (DriverCommand .SWITCH_TO_FRAME .equals (commandName )) {
303
- Object target = params .get ("id" );
304
- if (target instanceof Map ) {
305
- String elementId = (String ) ((Map <String ,Object >) target ).get ("ELEMENT" );
306
- params .put ("element" , elementId );
307
- params .remove ("id" );
308
-
309
- } else {
310
- renameParameter (params , "id" , "value" );
311
- }
312
287
313
288
} else if (DriverCommand .FIND_CHILD_ELEMENT .equals (commandName )
314
- || DriverCommand .FIND_CHILD_ELEMENTS .equals (commandName )
315
- || DriverCommand .CLICK_ELEMENT .equals (commandName )
316
- || DriverCommand .CLEAR_ELEMENT .equals (commandName )
317
- || DriverCommand .GET_ELEMENT_ATTRIBUTE .equals (commandName )
318
- || DriverCommand .GET_ELEMENT_TEXT .equals (commandName )
319
- || DriverCommand .SEND_KEYS_TO_ELEMENT .equals (commandName )
320
- || DriverCommand .IS_ELEMENT_SELECTED .equals (commandName )
321
- || DriverCommand .IS_ELEMENT_ENABLED .equals (commandName )
322
- || DriverCommand .IS_ELEMENT_DISPLAYED .equals (commandName )
323
- || DriverCommand .GET_ELEMENT_SIZE .equals (commandName )
324
- || DriverCommand .GET_ELEMENT_LOCATION .equals (commandName )
325
- || DriverCommand .GET_ELEMENT_TAG_NAME .equals (commandName )) {
289
+ || DriverCommand .FIND_CHILD_ELEMENTS .equals (commandName )) {
326
290
renameParameter (params , "id" , "element" );
327
291
328
292
} else if (DriverCommand .CLICK .equals (commandName )
@@ -349,11 +313,12 @@ private String serializeCommand(Command command) {
349
313
350
314
Map <String , Object > map = Maps .newHashMap ();
351
315
map .put ("to" , marionetteId != null ? marionetteId : "root" );
352
- map .put ("type " , commandName );
316
+ map .put ("name " , commandName );
353
317
if (command .getSessionId () != null ) {
354
- map .put ("session" , command .getSessionId ().toString ());
318
+ // See https://bugzilla.mozilla.org/show_bug.cgi?id=1073732
319
+ map .put ("sessionId" , new JsonToBeanConverter ().convert (Map .class , command .getSessionId ().toString ()));
355
320
}
356
- map .putAll ( params );
321
+ map .put ( "parameters" , params );
357
322
358
323
return new BeanToJsonConverter ().convert (map );
359
324
}
@@ -365,8 +330,8 @@ private void renameParameter(Map<String, Object> params, String origParName, Str
365
330
}
366
331
367
332
private void sendCommand (String commandAsString ) {
368
- String line = "" + commandAsString .length () + ":" + commandAsString + " " ;
369
- // System.out.println(line);
333
+ String line = "" + commandAsString .length () + ":" + commandAsString ;
334
+ System .out .println (line );
370
335
writer .write (line );
371
336
writer .flush ();
372
337
}
@@ -383,7 +348,7 @@ private String receiveResponse() throws IOException {
383
348
response .append (buf , 0 , len );
384
349
}
385
350
386
- // System.out.println("<- |" + response.toString() + "|");
351
+ System .out .println ("<- |" + response .toString () + "|" );
387
352
388
353
String [] parts = response .toString ().split (":" , 2 );
389
354
int length = Integer .parseInt (parts [0 ]);
0 commit comments