Skip to content

Commit

Permalink
Merge pull request #62 from melloware/59
Browse files Browse the repository at this point in the history
Fix #59: Added recordVideoDir option
  • Loading branch information
ia3andy authored Jul 3, 2024
2 parents fa0cd40 + e18514c commit ef0b0c0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
<tag>HEAD</tag>
</scm>
<properties>
<compiler-plugin.version>3.12.1</compiler-plugin.version>
<compiler-plugin.version>3.13.0</compiler-plugin.version>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>3.3.1</quarkus.version>
<playright.version>1.41.2</playright.version>
<playright.version>1.44.0</playright.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -75,4 +75,4 @@
</modules>
</profile>
</profiles>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -51,7 +54,12 @@ public Map<String, String> 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();
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -63,4 +68,4 @@ enum Browser {
WEBKIT
}

}
}

0 comments on commit ef0b0c0

Please sign in to comment.