|
19 | 19 | import org.junit.jupiter.api.Test; |
20 | 20 | import org.junit.jupiter.api.io.TempDir; |
21 | 21 |
|
| 22 | +import java.io.IOException; |
22 | 23 | import java.nio.file.Files; |
23 | 24 | import java.nio.file.Path; |
| 25 | +import java.util.List; |
| 26 | +import java.util.stream.Collectors; |
24 | 27 |
|
25 | 28 | import static org.junit.jupiter.api.Assertions.*; |
26 | 29 |
|
@@ -101,4 +104,25 @@ void shouldDeleteVideo(@TempDir Path videosDir) { |
101 | 104 | Path videoPath = page.video().path(); |
102 | 105 | assertFalse(Files.exists(videoPath)); |
103 | 106 | } |
| 107 | + |
| 108 | + @Test |
| 109 | + void shouldWaitForVideoFinishWhenPageIsClosed(@TempDir Path videosDir) throws IOException { |
| 110 | + try (Browser browser = browserType.launch(createLaunchOptions())) { |
| 111 | + BrowserContext context = browser.newContext( |
| 112 | + new Browser.NewContextOptions() |
| 113 | + .setRecordVideoDir(videosDir) |
| 114 | + .setRecordVideoSize(320, 240) |
| 115 | + .setViewportSize(320, 240)); |
| 116 | + Page page = context.newPage(); |
| 117 | + page.evaluate("() => document.body.style.backgroundColor = 'red'"); |
| 118 | + page.waitForTimeout(500); |
| 119 | + // First close page manually. |
| 120 | + page.close(); |
| 121 | + context.close(); |
| 122 | + } |
| 123 | + List<Path> files = Files.list(videosDir).collect(Collectors.toList()); |
| 124 | + assertEquals(1, files.size()); |
| 125 | + assertTrue(Files.exists(files.get(0))); |
| 126 | + assertTrue(Files.size(files.get(0)) > 0); |
| 127 | + } |
104 | 128 | } |
0 commit comments