From 87d9957486e10840d2aff0d2734523d3c964c11f Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 19 May 2021 05:45:17 +0000 Subject: [PATCH] fix: wait for video to finish even if page was closed (#447) --- .../microsoft/playwright/BrowserContext.java | 2 +- .../microsoft/playwright/TestScreencast.java | 24 +++++++++++++++++++ scripts/CLI_VERSION | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java b/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java index 60f12432..146e6382 100644 --- a/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java +++ b/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java @@ -37,7 +37,7 @@ import java.util.regex.Pattern; * // Create a new page inside context. * Page page = context.newPage(); * page.navigate("https://example.com"); - * // Dispose context once it"s no longer needed. + * // Dispose context once it is no longer needed. * context.close(); * } */ diff --git a/playwright/src/test/java/com/microsoft/playwright/TestScreencast.java b/playwright/src/test/java/com/microsoft/playwright/TestScreencast.java index d7361675..fdb35244 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestScreencast.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestScreencast.java @@ -19,8 +19,11 @@ package com.microsoft.playwright; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.List; +import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.*; @@ -101,4 +104,25 @@ public class TestScreencast extends TestBase { Path videoPath = page.video().path(); assertFalse(Files.exists(videoPath)); } + + @Test + void shouldWaitForVideoFinishWhenPageIsClosed(@TempDir Path videosDir) throws IOException { + try (Browser browser = browserType.launch(createLaunchOptions())) { + BrowserContext context = browser.newContext( + new Browser.NewContextOptions() + .setRecordVideoDir(videosDir) + .setRecordVideoSize(320, 240) + .setViewportSize(320, 240)); + Page page = context.newPage(); + page.evaluate("() => document.body.style.backgroundColor = 'red'"); + page.waitForTimeout(500); + // First close page manually. + page.close(); + context.close(); + } + List files = Files.list(videosDir).collect(Collectors.toList()); + assertEquals(1, files.size()); + assertTrue(Files.exists(files.get(0))); + assertTrue(Files.size(files.get(0)) > 0); + } } diff --git a/scripts/CLI_VERSION b/scripts/CLI_VERSION index fb648f03..d16091b0 100644 --- a/scripts/CLI_VERSION +++ b/scripts/CLI_VERSION @@ -1 +1 @@ -1.12.0-next-1621019018000 +1.12.0-next-1621402179000