From e18514cc7a000d048ee22a59564d8f84d33597aa Mon Sep 17 00:00:00 2001 From: melloware Date: Thu, 27 Jun 2024 16:47:33 -0400 Subject: [PATCH] Fix #59: Added recordVideoDir option --- pom.xml | 6 +++--- .../playwright/QuarkusPlaywrightManager.java | 14 +++++++++++++- .../io/quarkiverse/playwright/WithPlaywright.java | 7 ++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index fa1c185..18d501d 100644 --- a/pom.xml +++ b/pom.xml @@ -23,12 +23,12 @@ HEAD - 3.12.1 + 3.13.0 11 UTF-8 UTF-8 3.3.1 - 1.41.2 + 1.44.0 @@ -75,4 +75,4 @@ - + \ No newline at end of file diff --git a/testing/src/main/java/io/quarkiverse/playwright/QuarkusPlaywrightManager.java b/testing/src/main/java/io/quarkiverse/playwright/QuarkusPlaywrightManager.java index 9b4b3e6..97385e1 100644 --- a/testing/src/main/java/io/quarkiverse/playwright/QuarkusPlaywrightManager.java +++ b/testing/src/main/java/io/quarkiverse/playwright/QuarkusPlaywrightManager.java @@ -1,10 +1,13 @@ package io.quarkiverse.playwright; +import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import org.apache.commons.lang3.StringUtils; + import com.microsoft.playwright.Browser; import com.microsoft.playwright.BrowserContext; import com.microsoft.playwright.BrowserType; @@ -51,7 +54,12 @@ public Map start() { .setArgs(Arrays.asList(this.options.args())); this.playwrightBrowser = browser(playwright, this.options.browser()).launch( launchOptions); - this.playwrightContext = playwrightBrowser.newContext(); + + final Browser.NewContextOptions contextOptions = new Browser.NewContextOptions(); + if (StringUtils.isNotBlank(this.options.recordVideoDir())) { + contextOptions.setRecordVideoDir(Paths.get(this.options.recordVideoDir())); + } + this.playwrightContext = playwrightBrowser.newContext(contextOptions); return Collections.emptyMap(); } @@ -69,6 +77,10 @@ private static BrowserType browser(Playwright playwright, WithPlaywright.Browser @Override public void stop() { + if (this.playwrightContext != null) { + this.playwrightContext.close(); + this.playwrightContext = null; + } if (playwright != null) { playwright.close(); playwright = null; diff --git a/testing/src/main/java/io/quarkiverse/playwright/WithPlaywright.java b/testing/src/main/java/io/quarkiverse/playwright/WithPlaywright.java index 0c0a7d0..fc66eba 100644 --- a/testing/src/main/java/io/quarkiverse/playwright/WithPlaywright.java +++ b/testing/src/main/java/io/quarkiverse/playwright/WithPlaywright.java @@ -52,6 +52,11 @@ */ double slowMo() default 0; + /** + * Enables video recording for all pages into the specified directory. If not specified videos are not recorded. + */ + String recordVideoDir() default ""; + /** * Args for use to launch the browser */ @@ -63,4 +68,4 @@ enum Browser { WEBKIT } -} +} \ No newline at end of file