|
24 | 24 |
|
25 | 25 | import java.io.IOException; |
26 | 26 | import java.lang.reflect.Field; |
27 | | -import java.net.MalformedURLException; |
28 | 27 | import java.net.ServerSocket; |
29 | 28 | import java.nio.file.Files; |
30 | 29 | import java.nio.file.Path; |
@@ -63,7 +62,7 @@ void clearSystemProperties() { |
63 | 62 | } |
64 | 63 |
|
65 | 64 | @Test |
66 | | - void shouldThrowWhenBrowserPathIsInvalid(@TempDir Path tmpDir) throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException { |
| 65 | + void shouldThrowWhenBrowserPathIsInvalid(@TempDir Path tmpDir) throws NoSuchFieldException, IllegalAccessException { |
67 | 66 | Map<String,String> env = new HashMap<>(); |
68 | 67 |
|
69 | 68 | // On macOS we can only use 127.0.0.1, so pick unused port instead. |
@@ -114,12 +113,20 @@ void playwrightDriverDefaultImpl() { |
114 | 113 | } |
115 | 114 |
|
116 | 115 | @Test |
117 | | - void playwrightDriverAlternativeImpl() { |
| 116 | + void playwrightDriverAlternativeImpl() throws NoSuchFieldException, IllegalAccessException { |
| 117 | + // Reset instance field value to null for the test. |
| 118 | + Field field = Driver.class.getDeclaredField("instance"); |
| 119 | + field.setAccessible(true); |
| 120 | + Object value = field.get(Driver.class); |
| 121 | + field.set(Driver.class, null); |
| 122 | + |
118 | 123 | System.setProperty("playwright.driver.impl", "com.microsoft.playwright.impl.AlternativeDriver"); |
119 | 124 | RuntimeException thrown = |
120 | 125 | assertThrows( |
121 | 126 | RuntimeException.class, |
122 | 127 | () -> Driver.ensureDriverInstalled(Collections.emptyMap(), false)); |
123 | 128 | assertEquals("Failed to create driver", thrown.getMessage()); |
| 129 | + |
| 130 | + field.set(Driver.class, value); |
124 | 131 | } |
125 | 132 | } |
0 commit comments