Skip to content

Commit e372513

Browse files
authored
test: unflake playwrightDriverAlternativeImpl (#986)
1 parent b8e1e1d commit e372513

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

driver-bundle/src/test/java/com/microsoft/playwright/TestInstall.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import java.io.IOException;
2626
import java.lang.reflect.Field;
27-
import java.net.MalformedURLException;
2827
import java.net.ServerSocket;
2928
import java.nio.file.Files;
3029
import java.nio.file.Path;
@@ -63,7 +62,7 @@ void clearSystemProperties() {
6362
}
6463

6564
@Test
66-
void shouldThrowWhenBrowserPathIsInvalid(@TempDir Path tmpDir) throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
65+
void shouldThrowWhenBrowserPathIsInvalid(@TempDir Path tmpDir) throws NoSuchFieldException, IllegalAccessException {
6766
Map<String,String> env = new HashMap<>();
6867

6968
// On macOS we can only use 127.0.0.1, so pick unused port instead.
@@ -114,12 +113,20 @@ void playwrightDriverDefaultImpl() {
114113
}
115114

116115
@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+
118123
System.setProperty("playwright.driver.impl", "com.microsoft.playwright.impl.AlternativeDriver");
119124
RuntimeException thrown =
120125
assertThrows(
121126
RuntimeException.class,
122127
() -> Driver.ensureDriverInstalled(Collections.emptyMap(), false));
123128
assertEquals("Failed to create driver", thrown.getMessage());
129+
130+
field.set(Driver.class, value);
124131
}
125132
}

0 commit comments

Comments
 (0)