@@ -279,6 +279,10 @@ protected void setCommandExecutor(CommandExecutor executor) {
279
279
this .executor = executor ;
280
280
}
281
281
282
+ public synchronized void setCommandExecutionTimeout (Duration timeout ) {
283
+ executor .setCommandExecutionTimeout (timeout );
284
+ }
285
+
282
286
@ Override
283
287
public Capabilities getCapabilities () {
284
288
return capabilities ;
@@ -316,9 +320,10 @@ public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException
316
320
String base64EncodedPng = new String ((byte []) result , UTF_8 );
317
321
return outputType .convertFromBase64Png (base64EncodedPng );
318
322
} else {
319
- throw new RuntimeException (String .format ("Unexpected result for %s command: %s" ,
320
- DriverCommand .SCREENSHOT ,
321
- result == null ? "null" : result .getClass ().getName () + " instance" ));
323
+ throw new RuntimeException (String .format (
324
+ "Unexpected result for %s command: %s" ,
325
+ DriverCommand .SCREENSHOT ,
326
+ result == null ? "null" : result .getClass ().getName () + " instance" ));
322
327
}
323
328
}
324
329
@@ -438,14 +443,15 @@ public String getWindowHandle() {
438
443
public Object executeScript (String script , Object ... args ) {
439
444
if (!isJavascriptEnabled ()) {
440
445
throw new UnsupportedOperationException (
441
- "You must be using an underlying instance of WebDriver that supports executing javascript" );
446
+ "You must be using an underlying instance of WebDriver that supports executing javascript" );
442
447
}
443
448
444
449
// Escape the quote marks
445
450
script = script .replaceAll ("\" " , "\\ \" " );
446
451
447
- List <Object > convertedArgs = Stream .of (args ).map (new WebElementToJsonConverter ()).collect (
448
- Collectors .toList ());
452
+ List <Object > convertedArgs = Stream .of (args )
453
+ .map (new WebElementToJsonConverter ())
454
+ .collect (Collectors .toList ());
449
455
450
456
return execute (DriverCommand .EXECUTE_SCRIPT (script , convertedArgs )).getValue ();
451
457
}
@@ -454,14 +460,15 @@ public Object executeScript(String script, Object... args) {
454
460
public Object executeAsyncScript (String script , Object ... args ) {
455
461
if (!isJavascriptEnabled ()) {
456
462
throw new UnsupportedOperationException ("You must be using an underlying instance of " +
457
- "WebDriver that supports executing javascript" );
463
+ "WebDriver that supports executing javascript" );
458
464
}
459
465
460
466
// Escape the quote marks
461
467
script = script .replaceAll ("\" " , "\\ \" " );
462
468
463
- List <Object > convertedArgs = Stream .of (args ).map (new WebElementToJsonConverter ()).collect (
464
- Collectors .toList ());
469
+ List <Object > convertedArgs = Stream .of (args )
470
+ .map (new WebElementToJsonConverter ())
471
+ .collect (Collectors .toList ());
465
472
466
473
return execute (DriverCommand .EXECUTE_ASYNC_SCRIPT (script , convertedArgs )).getValue ();
467
474
}
@@ -596,15 +603,15 @@ public Mouse getMouse() {
596
603
597
604
@ Override
598
605
public VirtualAuthenticator addVirtualAuthenticator (VirtualAuthenticatorOptions options ) {
599
- String authenticatorId = (String )
600
- execute ( DriverCommand .ADD_VIRTUAL_AUTHENTICATOR , options .toMap ()).getValue ();
606
+ String authenticatorId = (String ) execute (
607
+ DriverCommand .ADD_VIRTUAL_AUTHENTICATOR , options .toMap ()).getValue ();
601
608
return new RemoteVirtualAuthenticator (authenticatorId );
602
609
}
603
610
604
611
@ Override
605
612
public void removeVirtualAuthenticator (VirtualAuthenticator authenticator ) {
606
613
execute (DriverCommand .REMOVE_VIRTUAL_AUTHENTICATOR ,
607
- ImmutableMap .of ("authenticatorId" , authenticator .getId ()));
614
+ ImmutableMap .of ("authenticatorId" , authenticator .getId ()));
608
615
}
609
616
610
617
/**
@@ -687,24 +694,24 @@ public Set<Cookie> getCookies() {
687
694
}
688
695
689
696
((Collection <?>) returned ).stream ()
690
- .map (o -> (Map <String , Object >) o )
691
- .map (rawCookie -> {
692
- // JSON object keys are defined in
693
- // https://w3c.github.io/webdriver/#dfn-table-for-cookie-conversion.
694
- Cookie .Builder builder =
695
- new Cookie .Builder ((String ) rawCookie .get ("name" ), (String ) rawCookie .get ("value" ))
696
- .path ((String ) rawCookie .get ("path" ))
697
- .domain ((String ) rawCookie .get ("domain" ))
698
- .isSecure (rawCookie .containsKey ("secure" ) && (Boolean ) rawCookie .get ("secure" ))
699
- .isHttpOnly (
700
- rawCookie .containsKey ("httpOnly" ) && (Boolean ) rawCookie .get ("httpOnly" ))
701
- .sameSite ((String ) rawCookie .get ("sameSite" ));
702
-
703
- Number expiryNum = (Number ) rawCookie .get ("expiry" );
704
- builder .expiresOn (expiryNum == null ? null : new Date (SECONDS .toMillis (expiryNum .longValue ())));
705
- return builder .build ();
706
- })
707
- .forEach (toReturn ::add );
697
+ .map (o -> (Map <String , Object >) o )
698
+ .map (rawCookie -> {
699
+ // JSON object keys are defined in
700
+ // https://w3c.github.io/webdriver/#dfn-table-for-cookie-conversion.
701
+ Cookie .Builder builder =
702
+ new Cookie .Builder ((String ) rawCookie .get ("name" ), (String ) rawCookie .get ("value" ))
703
+ .path ((String ) rawCookie .get ("path" ))
704
+ .domain ((String ) rawCookie .get ("domain" ))
705
+ .isSecure (rawCookie .containsKey ("secure" ) && (Boolean ) rawCookie .get ("secure" ))
706
+ .isHttpOnly (
707
+ rawCookie .containsKey ("httpOnly" ) && (Boolean ) rawCookie .get ("httpOnly" ))
708
+ .sameSite ((String ) rawCookie .get ("sameSite" ));
709
+
710
+ Number expiryNum = (Number ) rawCookie .get ("expiry" );
711
+ builder .expiresOn (expiryNum == null ? null : new Date (SECONDS .toMillis (expiryNum .longValue ())));
712
+ return builder .build ();
713
+ })
714
+ .forEach (toReturn ::add );
708
715
709
716
return toReturn ;
710
717
}
@@ -903,10 +910,10 @@ public WebDriver frame(int frameIndex) {
903
910
public WebDriver frame (String frameName ) {
904
911
String name = frameName .replaceAll ("(['\" \\ \\ #.:;,!?+<>=~*^$|%&@`{}\\ -/\\ [\\ ]\\ (\\ )])" , "\\ \\ $1" );
905
912
List <WebElement > frameElements = RemoteWebDriver .this .findElements (
906
- By .cssSelector ("frame[name='" + name + "'],iframe[name='" + name + "']" ));
913
+ By .cssSelector ("frame[name='" + name + "'],iframe[name='" + name + "']" ));
907
914
if (frameElements .size () == 0 ) {
908
915
frameElements = RemoteWebDriver .this .findElements (
909
- By .cssSelector ("frame#" + name + ",iframe#" + name ));
916
+ By .cssSelector ("frame#" + name + ",iframe#" + name ));
910
917
}
911
918
if (frameElements .size () == 0 ) {
912
919
throw new NoSuchFrameException ("No frame element found by name or id " + frameName );
@@ -1028,16 +1035,16 @@ public String getId() {
1028
1035
@ Override
1029
1036
public void addCredential (Credential credential ) {
1030
1037
execute (DriverCommand .ADD_CREDENTIAL ,
1031
- new ImmutableMap .Builder <String , Object >()
1032
- .putAll (credential .toMap ())
1033
- .put ("authenticatorId" , id )
1034
- .build ());
1038
+ new ImmutableMap .Builder <String , Object >()
1039
+ .putAll (credential .toMap ())
1040
+ .put ("authenticatorId" , id )
1041
+ .build ());
1035
1042
}
1036
1043
1037
1044
@ Override
1038
1045
public List <Credential > getCredentials () {
1039
- List <Map <String , Object >> response = (List <Map <String , Object >>)
1040
- execute ( DriverCommand .GET_CREDENTIALS , ImmutableMap .of ("authenticatorId" , id )).getValue ();
1046
+ List <Map <String , Object >> response = (List <Map <String , Object >>) execute (
1047
+ DriverCommand .GET_CREDENTIALS , ImmutableMap .of ("authenticatorId" , id )).getValue ();
1041
1048
return response .stream ().map (Credential ::fromMap ).collect (Collectors .toList ());
1042
1049
}
1043
1050
@@ -1049,7 +1056,7 @@ public void removeCredential(byte[] credentialId) {
1049
1056
@ Override
1050
1057
public void removeCredential (String credentialId ) {
1051
1058
execute (DriverCommand .REMOVE_CREDENTIAL ,
1052
- ImmutableMap .of ("authenticatorId" , id , "credentialId" , credentialId ));
1059
+ ImmutableMap .of ("authenticatorId" , id , "credentialId" , credentialId ));
1053
1060
}
1054
1061
1055
1062
@ Override
@@ -1060,7 +1067,7 @@ public void removeAllCredentials() {
1060
1067
@ Override
1061
1068
public void setUserVerified (boolean verified ) {
1062
1069
execute (DriverCommand .SET_USER_VERIFIED ,
1063
- ImmutableMap .of ("authenticatorId" , id , "isUserVerified" , verified ));
1070
+ ImmutableMap .of ("authenticatorId" , id , "isUserVerified" , verified ));
1064
1071
}
1065
1072
}
1066
1073
@@ -1087,10 +1094,10 @@ public String toString() {
1087
1094
}
1088
1095
1089
1096
return String .format (
1090
- "%s: %s on %s (%s)" ,
1091
- getClass ().getSimpleName (),
1092
- caps .getBrowserName (),
1093
- platform ,
1094
- getSessionId ());
1097
+ "%s: %s on %s (%s)" ,
1098
+ getClass ().getSimpleName (),
1099
+ caps .getBrowserName (),
1100
+ platform ,
1101
+ getSessionId ());
1095
1102
}
1096
1103
}
0 commit comments