Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #59: Added recordVideoDir option #62

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ia3andy not sure if this was necessary but it felt safe? I couldn't tell from Microsoft docs whether playwrite.close() closes the context also?

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
}

}
}
Loading