1818
1919import com .microsoft .playwright .impl .Driver ;
2020import com .microsoft .playwright .impl .DriverJar ;
21- import org .junit .jupiter .api .*;
21+ import org .junit .jupiter .api .BeforeEach ;
22+ import org .junit .jupiter .api .Test ;
2223import org .junit .jupiter .api .io .TempDir ;
2324
2425import java .io .IOException ;
26+ import java .lang .reflect .Field ;
27+ import java .net .MalformedURLException ;
2528import java .net .ServerSocket ;
2629import java .nio .file .Files ;
2730import java .nio .file .Path ;
3033import java .util .Map ;
3134import java .util .concurrent .TimeUnit ;
3235
33- import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
34- import static org .junit .jupiter .api .Assertions .assertEquals ;
35- import static org .junit .jupiter .api .Assertions .assertThrows ;
36- import static org .junit .jupiter .api .Assertions .assertTrue ;
36+ import static org .junit .jupiter .api .Assertions .*;
3737
3838public class TestInstall {
3939 private static boolean isPortAvailable (int port ) {
@@ -63,8 +63,7 @@ void clearSystemProperties() {
6363 }
6464
6565 @ Test
66- @ Tags ({@ Tag ("isolated" ), @ Tag ("driverThrowTest" )})
67- void shouldThrowWhenBrowserPathIsInvalid (@ TempDir Path tmpDir ) {
66+ void shouldThrowWhenBrowserPathIsInvalid (@ TempDir Path tmpDir ) throws MalformedURLException , ClassNotFoundException , NoSuchMethodException , NoSuchFieldException , IllegalAccessException {
6867 Map <String ,String > env = new HashMap <>();
6968
7069 // On macOS we can only use 127.0.0.1, so pick unused port instead.
@@ -74,8 +73,19 @@ void shouldThrowWhenBrowserPathIsInvalid(@TempDir Path tmpDir) {
7473 env .put ("PLAYWRIGHT_BROWSERS_PATH" , tmpDir .toString ());
7574 env .put ("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD" , "false" );
7675
77- assertThrows (RuntimeException .class , () -> Driver .ensureDriverInstalled (env , true ));
78- assertThrows (RuntimeException .class , () -> Driver .ensureDriverInstalled (env , true ));
76+ // Reset instance field value to null for the test.
77+ Field field = Driver .class .getDeclaredField ("instance" );
78+ field .setAccessible (true );
79+ Object value = field .get (Driver .class );
80+ field .set (Driver .class , null );
81+
82+ for (int i = 0 ; i < 2 ; i ++){
83+ RuntimeException exception = assertThrows (RuntimeException .class , () -> Driver .ensureDriverInstalled (env , true ));
84+ String message = exception .getMessage ();
85+ assertTrue (message .contains ("Failed to create driver" ), message );
86+ }
87+
88+ field .set (Driver .class , value );
7989 }
8090
8191 @ Test
0 commit comments