|
1 | 1 | package uk.co.evoco.webdriver.utils; |
2 | 2 |
|
3 | 3 | import org.junit.jupiter.api.Test; |
| 4 | +import org.openqa.selenium.ElementClickInterceptedException; |
4 | 5 | import org.openqa.selenium.InvalidArgumentException; |
| 6 | +import org.openqa.selenium.StaleElementReferenceException; |
5 | 7 |
|
6 | 8 | import java.util.ArrayList; |
7 | 9 | import java.util.List; |
8 | 10 |
|
9 | | -import static org.junit.jupiter.api.Assertions.assertEquals; |
10 | | -import static org.junit.jupiter.api.Assertions.assertThrows; |
11 | | - |
| 11 | +import static org.junit.jupiter.api.Assertions.*; |
| 12 | +import static org.junit.jupiter.api.Assertions.fail; |
12 | 13 |
|
13 | 14 | public class TolerantExceptionHandlerTests { |
14 | 15 |
|
@@ -66,4 +67,53 @@ public void testIgnoresClassesInTolerantExceptionListThatAreNotThrowable () thro |
66 | 67 | ArithmeticException inputException = new ArithmeticException(); |
67 | 68 | assertEquals(inputException, handler.propagateIfNotIgnored(inputException)); |
68 | 69 | } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void testShouldNotPropagateExceptionOnElementClickInterceptedException() throws Throwable { |
| 73 | + List<String> exceptions = new ArrayList<>(); |
| 74 | + exceptions.add("ElementClickInterceptedException"); |
| 75 | + TolerantExceptionHandler tolerantExceptionHandler = new TolerantExceptionHandler(exceptions); |
| 76 | + try { |
| 77 | + tolerantExceptionHandler.propagateIfNotIgnored(new ElementClickInterceptedException("Hello")); |
| 78 | + assertTrue(true); |
| 79 | + } catch(Exception e) { |
| 80 | + fail(); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void testShouldNotPropagateExceptionOnStaleElementException() throws Throwable { |
| 86 | + List<String> exceptions = new ArrayList<>(); |
| 87 | + exceptions.add("StaleElementReferenceException"); |
| 88 | + TolerantExceptionHandler tolerantExceptionHandler = new TolerantExceptionHandler(exceptions); |
| 89 | + try { |
| 90 | + tolerantExceptionHandler.propagateIfNotIgnored(new StaleElementReferenceException("Hello")); |
| 91 | + assertTrue(true); |
| 92 | + } catch(Exception e) { |
| 93 | + fail(); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void testShouldNotPropagateExceptionOnStaleElementExceptionWithPacakgeName() throws Throwable { |
| 99 | + List<String> exceptions = new ArrayList<>(); |
| 100 | + exceptions.add("org.openqa.selenium.StaleElementReferenceException"); |
| 101 | + TolerantExceptionHandler tolerantExceptionHandler = new TolerantExceptionHandler(exceptions); |
| 102 | + try { |
| 103 | + tolerantExceptionHandler.propagateIfNotIgnored(new StaleElementReferenceException("Hello")); |
| 104 | + assertTrue(true); |
| 105 | + } catch(Exception e) { |
| 106 | + fail(); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + public void testShouldPropagateExceptionWhenUnToleratedExceptionDetected() throws Throwable { |
| 112 | + List<String> exceptions = new ArrayList<>(); |
| 113 | + exceptions.add("StaleElementReferenceException"); |
| 114 | + TolerantExceptionHandler tolerantExceptionHandler = new TolerantExceptionHandler(exceptions); |
| 115 | + assertThrows(Throwable.class, () -> { |
| 116 | + tolerantExceptionHandler.propagateIfNotIgnored(new Exception("Hello")); |
| 117 | + }); |
| 118 | + } |
69 | 119 | } |
0 commit comments