1717
1818package org .openqa .selenium .support .events ;
1919
20- import static org .assertj .core .api .Assertions .assertThat ;
21- import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
22- import static org .assertj .core .api .Assertions .assertThatNoException ;
20+ import static org .assertj .core .api .Assertions .*;
2321import static org .mockito .ArgumentMatchers .any ;
2422import static org .mockito .Mockito .doNothing ;
2523import static org .mockito .Mockito .mock ;
@@ -1050,6 +1048,30 @@ public void beforeAnyCall(Object target, Method method, Object[] args) {
10501048 assertThatNoException ().isThrownBy (decorated ::getWindowHandle );
10511049 }
10521050
1051+ @ Test
1052+ void shouldReThrowExceptionInBeforeAnyCall () {
1053+ WebDriver driver = mock (WebDriver .class );
1054+ WebDriverListener listener =
1055+ new WebDriverListener () {
1056+
1057+ @ Override
1058+ public boolean throwsExceptions () {
1059+ return true ;
1060+ }
1061+
1062+ @ Override
1063+ public void beforeAnyCall (Object target , Method method , Object [] args ) {
1064+ throw new RuntimeException ("listener" );
1065+ }
1066+ };
1067+
1068+ WebDriver decorated = new EventFiringDecorator <>(listener ).decorate (driver );
1069+
1070+ assertThatExceptionOfType (WebDriverListenerException .class )
1071+ .isThrownBy (decorated ::getWindowHandle )
1072+ .withMessage ("beforeAnyCall" );
1073+ }
1074+
10531075 @ Test
10541076 void shouldSuppressExceptionInBeforeClassMethodCall () {
10551077 WebDriver driver = mock (WebDriver .class );
@@ -1066,6 +1088,30 @@ public void beforeAnyWebDriverCall(WebDriver driver, Method method, Object[] arg
10661088 assertThatNoException ().isThrownBy (decorated ::getWindowHandle );
10671089 }
10681090
1091+ @ Test
1092+ void shouldReThrowExceptionInBeforeClassMethodCall () {
1093+ WebDriver driver = mock (WebDriver .class );
1094+ WebDriverListener listener =
1095+ new WebDriverListener () {
1096+
1097+ @ Override
1098+ public boolean throwsExceptions () {
1099+ return true ;
1100+ }
1101+
1102+ @ Override
1103+ public void beforeAnyWebDriverCall (WebDriver driver , Method method , Object [] args ) {
1104+ throw new RuntimeException ("listener" );
1105+ }
1106+ };
1107+
1108+ WebDriver decorated = new EventFiringDecorator <>(listener ).decorate (driver );
1109+
1110+ assertThatExceptionOfType (WebDriverListenerException .class )
1111+ .isThrownBy (decorated ::getWindowHandle )
1112+ .withMessageStartingWith ("Exception executing listener method " );
1113+ }
1114+
10691115 @ Test
10701116 void shouldSuppressExceptionInBeforeMethod () {
10711117 WebDriver driver = mock (WebDriver .class );
@@ -1082,6 +1128,30 @@ public void beforeGetWindowHandle(WebDriver driver) {
10821128 assertThatNoException ().isThrownBy (decorated ::getWindowHandle );
10831129 }
10841130
1131+ @ Test
1132+ void shouldReThrowExceptionInBeforeMethod () {
1133+ WebDriver driver = mock (WebDriver .class );
1134+ WebDriverListener listener =
1135+ new WebDriverListener () {
1136+
1137+ @ Override
1138+ public boolean throwsExceptions () {
1139+ return true ;
1140+ }
1141+
1142+ @ Override
1143+ public void beforeGetWindowHandle (WebDriver driver ) {
1144+ throw new RuntimeException ("listener" );
1145+ }
1146+ };
1147+
1148+ WebDriver decorated = new EventFiringDecorator <>(listener ).decorate (driver );
1149+
1150+ assertThatExceptionOfType (WebDriverListenerException .class )
1151+ .isThrownBy (decorated ::getWindowHandle )
1152+ .withMessageStartingWith ("Exception executing listener method " );
1153+ }
1154+
10851155 @ Test
10861156 void shouldSuppressExceptionInAfterAnyCall () {
10871157 WebDriver driver = mock (WebDriver .class );
@@ -1098,6 +1168,30 @@ public void afterAnyCall(Object target, Method method, Object[] args, Object res
10981168 assertThatNoException ().isThrownBy (decorated ::getWindowHandle );
10991169 }
11001170
1171+ @ Test
1172+ void shouldReThrowExceptionInAfterAnyCall () {
1173+ WebDriver driver = mock (WebDriver .class );
1174+ WebDriverListener listener =
1175+ new WebDriverListener () {
1176+
1177+ @ Override
1178+ public boolean throwsExceptions () {
1179+ return true ;
1180+ }
1181+
1182+ @ Override
1183+ public void afterAnyCall (Object target , Method method , Object [] args , Object result ) {
1184+ throw new RuntimeException ("listener" );
1185+ }
1186+ };
1187+
1188+ WebDriver decorated = new EventFiringDecorator <>(listener ).decorate (driver );
1189+
1190+ assertThatExceptionOfType (WebDriverListenerException .class )
1191+ .isThrownBy (decorated ::getWindowHandle )
1192+ .withMessage ("afterAnyCall" );
1193+ }
1194+
11011195 @ Test
11021196 void shouldSuppressExceptionInAfterClassMethodCall () {
11031197 WebDriver driver = mock (WebDriver .class );
@@ -1115,6 +1209,31 @@ public void afterAnyWebDriverCall(
11151209 assertThatNoException ().isThrownBy (decorated ::getWindowHandle );
11161210 }
11171211
1212+ @ Test
1213+ void shouldReThrowExceptionInAfterClassMethodCall () {
1214+ WebDriver driver = mock (WebDriver .class );
1215+ WebDriverListener listener =
1216+ new WebDriverListener () {
1217+
1218+ @ Override
1219+ public boolean throwsExceptions () {
1220+ return true ;
1221+ }
1222+
1223+ @ Override
1224+ public void afterAnyWebDriverCall (
1225+ WebDriver driver , Method method , Object [] args , Object result ) {
1226+ throw new RuntimeException ("listener" );
1227+ }
1228+ };
1229+
1230+ WebDriver decorated = new EventFiringDecorator <>(listener ).decorate (driver );
1231+
1232+ assertThatExceptionOfType (WebDriverListenerException .class )
1233+ .isThrownBy (decorated ::getWindowHandle )
1234+ .withMessageStartingWith ("Exception executing listener method " );
1235+ }
1236+
11181237 @ Test
11191238 void shouldSuppressExceptionInAfterMethod () {
11201239 WebDriver driver = mock (WebDriver .class );
@@ -1131,6 +1250,30 @@ public void afterGetWindowHandle(WebDriver driver, String result) {
11311250 assertThatNoException ().isThrownBy (decorated ::getWindowHandle );
11321251 }
11331252
1253+ @ Test
1254+ void shouldReThrowExceptionInAfterMethod () {
1255+ WebDriver driver = mock (WebDriver .class );
1256+ WebDriverListener listener =
1257+ new WebDriverListener () {
1258+
1259+ @ Override
1260+ public boolean throwsExceptions () {
1261+ return true ;
1262+ }
1263+
1264+ @ Override
1265+ public void afterGetWindowHandle (WebDriver driver , String result ) {
1266+ throw new RuntimeException ("listener" );
1267+ }
1268+ };
1269+
1270+ WebDriver decorated = new EventFiringDecorator <>(listener ).decorate (driver );
1271+
1272+ assertThatExceptionOfType (WebDriverListenerException .class )
1273+ .isThrownBy (decorated ::getWindowHandle )
1274+ .withMessageStartingWith ("Exception executing listener method " );
1275+ }
1276+
11341277 @ Test
11351278 void shouldSuppressExceptionInOnError () {
11361279 WebDriver driver = mock (WebDriver .class );
0 commit comments