5050import org .openqa .selenium .SearchContext ;
5151import org .openqa .selenium .SessionNotCreatedException ;
5252import org .openqa .selenium .WebDriver ;
53+ import org .openqa .selenium .WebDriverException ;
5354import org .openqa .selenium .WebElement ;
5455import org .openqa .selenium .WindowType ;
5556
@@ -82,7 +83,7 @@ public void constructorShouldThrowIfExecutorIsNull() {
8283
8384 @ Test
8485 public void constructorShouldThrowIfExecutorThrowsOnAnAttemptToStartASession () throws IOException {
85- CommandExecutor executor = prepareExecutorMock (exceptionalResponder );
86+ CommandExecutor executor = prepareExecutorMock (exceptionResponder );
8687 assertThatExceptionOfType (SessionNotCreatedException .class )
8788 .isThrownBy (() -> new RemoteWebDriver (executor , new ImmutableCapabilities ()));
8889
@@ -918,6 +919,35 @@ public void canHandleElementClickCommand() throws IOException {
918919 new CommandPayload (DriverCommand .CLICK_ELEMENT , ImmutableMap .of ("id" , element .getId ())));
919920 }
920921
922+ @ Test
923+ public void canHandleExceptionsThrownByCommandExecutor () throws IOException {
924+ CommandExecutor executor = prepareExecutorMock (
925+ echoCapabilities , webDriverExceptionResponder );
926+
927+ RemoteWebDriver driver = new RemoteWebDriver (executor , new ImmutableCapabilities (
928+ "browserName" , "cheese" , "platformName" , "WINDOWS" ));
929+ RemoteWebElement element = new RemoteWebElement ();
930+ element .setParent (driver );
931+ String elementId = UUID .randomUUID ().toString ();
932+ element .setId (elementId );
933+ element .setFoundBy (driver , "id" , "test" );
934+
935+ assertThatExceptionOfType (WebDriverException .class )
936+ .isThrownBy (element ::click )
937+ .withMessageStartingWith ("BOOM!!!" )
938+ .withMessageContaining ("Build info: " )
939+ .withMessageContaining (
940+ "Driver info: driver.version: RemoteWebDriver" )
941+ .withMessageContaining (String .format (
942+ "Command: [%s, clickElement {id=%s}]" , driver .getSessionId (), elementId ))
943+ .withMessageContaining (String .format (
944+ "Element: [[RemoteWebDriver: cheese on WINDOWS (%s)] -> id: test]" , driver .getSessionId ()));
945+
946+ verifyCommands (
947+ executor , driver .getSessionId (),
948+ new CommandPayload (DriverCommand .CLICK_ELEMENT , ImmutableMap .of ("id" , element .getId ())));
949+ }
950+
921951 @ Test
922952 public void canHandleElementClearCommand () throws IOException {
923953 CommandExecutor executor = prepareExecutorMock (echoCapabilities , nullValueResponder );
@@ -1052,7 +1082,7 @@ public void canHandleElementGeTextCommand() throws IOException {
10521082 }
10531083
10541084 @ Test
1055- public void canHandleElementGeTagNameCommand () throws IOException {
1085+ public void canHandleElementGetTagNameCommand () throws IOException {
10561086 CommandExecutor executor = prepareExecutorMock (echoCapabilities , valueResponder ("div" ));
10571087
10581088 RemoteWebDriver driver = new RemoteWebDriver (executor , new ImmutableCapabilities ());
@@ -1070,7 +1100,7 @@ public void canHandleElementGeTagNameCommand() throws IOException {
10701100 }
10711101
10721102 @ Test
1073- public void canHandleElementGeLocationCommand () throws IOException {
1103+ public void canHandleElementGetLocationCommand () throws IOException {
10741104 CommandExecutor executor = prepareExecutorMock (
10751105 echoCapabilities , valueResponder (ImmutableMap .of ("x" , 10 , "y" , 20 )));
10761106
@@ -1089,9 +1119,9 @@ public void canHandleElementGeLocationCommand() throws IOException {
10891119 }
10901120
10911121 @ Test
1092- public void canHandleElementGeSizeCommand () throws IOException {
1122+ public void canHandleElementGetSizeCommand () throws IOException {
10931123 CommandExecutor executor = prepareExecutorMock (
1094- echoCapabilities , valueResponder (ImmutableMap .of ("width" , 100 , "height" , 200 )));
1124+ echoCapabilities , valueResponder (ImmutableMap .of ("width" , 100 , "height" , 200 )));
10951125
10961126 RemoteWebDriver driver = new RemoteWebDriver (executor , new ImmutableCapabilities ());
10971127 RemoteWebElement element = new RemoteWebElement ();
@@ -1107,7 +1137,7 @@ public void canHandleElementGeSizeCommand() throws IOException {
11071137 }
11081138
11091139 @ Test
1110- public void canHandleElementGeRectCommand () throws IOException {
1140+ public void canHandleElementGetRectCommand () throws IOException {
11111141 CommandExecutor executor = prepareExecutorMock (
11121142 echoCapabilities ,
11131143 valueResponder (ImmutableMap .of ("x" , 10 , "y" , 20 , "width" , 100 , "height" , 200 )));
@@ -1219,10 +1249,14 @@ private boolean isWebElement(Object value) {
12191249 return null ;
12201250 };
12211251
1222- private final Function <Command , Response > exceptionalResponder = cmd -> {
1252+ private final Function <Command , Response > exceptionResponder = cmd -> {
12231253 throw new InternalError ("BOOM!!!" );
12241254 };
12251255
1256+ private final Function <Command , Response > webDriverExceptionResponder = cmd -> {
1257+ throw new WebDriverException ("BOOM!!!" );
1258+ };
1259+
12261260 private final Function <Command , Response > nullValueResponder = valueResponder (null );
12271261
12281262 private Function <Command , Response > valueResponder (Object value ) {
0 commit comments