From 64f7a059afaa95b299a5ac8c63d19f72c2ef9e26 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 1 Aug 2022 15:01:43 -0700 Subject: [PATCH] fix: prevent video.saveAs() from hanging (#1020) --- .../com/microsoft/playwright/impl/VideoImpl.java | 3 +++ .../com/microsoft/playwright/TestScreencast.java | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/VideoImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/VideoImpl.java index 3dfb2b7c..a0e8d138 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/VideoImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/VideoImpl.java @@ -72,6 +72,9 @@ class VideoImpl implements Video { @Override public void saveAs(Path path) { page.withLogging("Video.saveAs", () -> { + if (!page.isClosed()) { + throw new PlaywrightException("Page is not yet closed. Close the page prior to calling saveAs"); + } try { waitForArtifact().saveAs(path); } catch (PlaywrightException e) { diff --git a/playwright/src/test/java/com/microsoft/playwright/TestScreencast.java b/playwright/src/test/java/com/microsoft/playwright/TestScreencast.java index ec7a8312..1cff3b07 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestScreencast.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestScreencast.java @@ -127,4 +127,17 @@ public class TestScreencast extends TestBase { assertTrue(Files.exists(files.get(0))); assertTrue(Files.size(files.get(0)) > 0); } + + @Test + void shouldErrorIfPageNotClosedBeforeSaveAs(@TempDir Path tmpDir) { + try (Page page = browser.newPage(new Browser.NewPageOptions().setRecordVideoDir(tmpDir))) { + page.navigate(server.PREFIX + "/grid.html"); + Path outPath = tmpDir.resolve("some-video.webm"); + Video video = page.video(); + PlaywrightException exception = assertThrows(PlaywrightException.class, () -> video.saveAs(outPath)); + assertTrue( + exception.getMessage().contains("Page is not yet closed. Close the page prior to calling saveAs"), + exception.getMessage()); + } + } }