@@ -85,7 +85,10 @@ public void constructorShouldThrowIfExecutorIsNull() {
85
85
public void constructorShouldThrowIfExecutorThrowsOnAnAttemptToStartASession () {
86
86
CommandExecutor executor = prepareExecutorMock (exceptionResponder );
87
87
assertThatExceptionOfType (SessionNotCreatedException .class )
88
- .isThrownBy (() -> new RemoteWebDriver (executor , new ImmutableCapabilities ()));
88
+ .isThrownBy (() -> new RemoteWebDriver (executor , new ImmutableCapabilities ()))
89
+ .withMessageContaining ("Build info: " )
90
+ .withMessageContaining ("Driver info: org.openqa.selenium.remote.RemoteWebDriver" )
91
+ .withMessageContaining ("Command: [null, newSession {desiredCapabilities=Capabilities {}}]" );
89
92
90
93
verifyCommands (executor , null ); // no commands
91
94
}
@@ -978,6 +981,72 @@ public void canHandleGeneralExceptionThrownByCommandExecutor() {
978
981
new CommandPayload (DriverCommand .CLICK_ELEMENT , ImmutableMap .of ("id" , element .getId ())));
979
982
}
980
983
984
+ @ Test
985
+ public void canHandleWebDriverExceptionReturnedByCommandExecutor () {
986
+ CommandExecutor executor = prepareExecutorMock (
987
+ echoCapabilities , errorResponder ("element click intercepted" , new WebDriverException ("BOOM!!!" )));
988
+
989
+ RemoteWebDriver driver = new RemoteWebDriver (executor , new ImmutableCapabilities (
990
+ "browserName" , "cheese" ));
991
+ RemoteWebElement element = new RemoteWebElement ();
992
+ element .setParent (driver );
993
+ String elementId = UUID .randomUUID ().toString ();
994
+ element .setId (elementId );
995
+ element .setFoundBy (driver , "id" , "test" );
996
+
997
+ assertThatExceptionOfType (WebDriverException .class )
998
+ .isThrownBy (element ::click )
999
+ .withMessageStartingWith ("BOOM!!!" )
1000
+ .withMessageContaining ("Build info: " )
1001
+ .withMessageContaining (
1002
+ "Driver info: org.openqa.selenium.remote.RemoteWebDriver" )
1003
+ .withMessageContaining (String .format (
1004
+ "Session ID: %s" , driver .getSessionId ()))
1005
+ .withMessageContaining (String .format (
1006
+ "%s" , driver .getCapabilities ()))
1007
+ .withMessageContaining (String .format (
1008
+ "Command: [%s, clickElement {id=%s}]" , driver .getSessionId (), elementId ))
1009
+ .withMessageContaining (String .format (
1010
+ "Element: [[RemoteWebDriver: cheese on ANY (%s)] -> id: test]" , driver .getSessionId ()));
1011
+
1012
+ verifyCommands (
1013
+ executor , driver .getSessionId (),
1014
+ new CommandPayload (DriverCommand .CLICK_ELEMENT , ImmutableMap .of ("id" , element .getId ())));
1015
+ }
1016
+
1017
+ @ Test
1018
+ public void canHandleResponseWithErrorCodeButNoExceptionReturnedByCommandExecutor () {
1019
+ CommandExecutor executor = prepareExecutorMock (
1020
+ echoCapabilities , errorResponder ("element click intercepted" , "BOOM!!!" ));
1021
+
1022
+ RemoteWebDriver driver = new RemoteWebDriver (executor , new ImmutableCapabilities (
1023
+ "browserName" , "cheese" ));
1024
+ RemoteWebElement element = new RemoteWebElement ();
1025
+ element .setParent (driver );
1026
+ String elementId = UUID .randomUUID ().toString ();
1027
+ element .setId (elementId );
1028
+ element .setFoundBy (driver , "id" , "test" );
1029
+
1030
+ assertThatExceptionOfType (WebDriverException .class )
1031
+ .isThrownBy (element ::click )
1032
+ .withMessageStartingWith ("BOOM!!!" )
1033
+ .withMessageContaining ("Build info: " )
1034
+ .withMessageContaining (
1035
+ "Driver info: org.openqa.selenium.remote.RemoteWebDriver" )
1036
+ .withMessageContaining (String .format (
1037
+ "Session ID: %s" , driver .getSessionId ()))
1038
+ .withMessageContaining (String .format (
1039
+ "%s" , driver .getCapabilities ()))
1040
+ .withMessageContaining (String .format (
1041
+ "Command: [%s, clickElement {id=%s}]" , driver .getSessionId (), elementId ))
1042
+ .withMessageContaining (String .format (
1043
+ "Element: [[RemoteWebDriver: cheese on ANY (%s)] -> id: test]" , driver .getSessionId ()));
1044
+
1045
+ verifyCommands (
1046
+ executor , driver .getSessionId (),
1047
+ new CommandPayload (DriverCommand .CLICK_ELEMENT , ImmutableMap .of ("id" , element .getId ())));
1048
+ }
1049
+
981
1050
@ Test
982
1051
public void canHandleElementClearCommand () {
983
1052
CommandExecutor executor = prepareExecutorMock (echoCapabilities , nullValueResponder );
@@ -1300,6 +1369,17 @@ private Function<Command, Response> valueResponder(Object value) {
1300
1369
};
1301
1370
}
1302
1371
1372
+ private Function <Command , Response > errorResponder (String state , Object value ) {
1373
+ return cmd -> {
1374
+ Response response = new Response ();
1375
+ response .setState (state );
1376
+ response .setStatus (new ErrorCodes ().toStatus (state , Optional .of (400 )));
1377
+ response .setValue (value );
1378
+ response .setSessionId (cmd .getSessionId () != null ? cmd .getSessionId ().toString () : null );
1379
+ return response ;
1380
+ };
1381
+ }
1382
+
1303
1383
private final Function <Command , Response > echoCapabilities = cmd -> {
1304
1384
Response response = new Response ();
1305
1385
response .setValue (
0 commit comments