diff --git a/playwright/src/main/java/com/microsoft/playwright/Browser.java b/playwright/src/main/java/com/microsoft/playwright/Browser.java index fb6fda7f..a8af906c 100644 --- a/playwright/src/main/java/com/microsoft/playwright/Browser.java +++ b/playwright/src/main/java/com/microsoft/playwright/Browser.java @@ -142,6 +142,11 @@ public interface Browser extends AutoCloseable { * be scaled down if necessary to fit the specified size. */ public RecordVideoSize recordVideoSize; + /** + * Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}. See {@link + * Page#emulateMedia Page.emulateMedia()} for more details. Defaults to {@code "no-preference"}. + */ + public ReducedMotion reducedMotion; /** * Emulates consistent window screen size available inside web page via {@code window.screen}. Is only used when the {@code viewport} * is set. @@ -261,6 +266,10 @@ public interface Browser extends AutoCloseable { this.recordVideoSize = recordVideoSize; return this; } + public NewContextOptions setReducedMotion(ReducedMotion reducedMotion) { + this.reducedMotion = reducedMotion; + return this; + } public NewContextOptions setScreenSize(int width, int height) { return setScreenSize(new ScreenSize(width, height)); } @@ -379,6 +388,11 @@ public interface Browser extends AutoCloseable { * be scaled down if necessary to fit the specified size. */ public RecordVideoSize recordVideoSize; + /** + * Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}. See {@link + * Page#emulateMedia Page.emulateMedia()} for more details. Defaults to {@code "no-preference"}. + */ + public ReducedMotion reducedMotion; /** * Emulates consistent window screen size available inside web page via {@code window.screen}. Is only used when the {@code viewport} * is set. @@ -498,6 +512,10 @@ public interface Browser extends AutoCloseable { this.recordVideoSize = recordVideoSize; return this; } + public NewPageOptions setReducedMotion(ReducedMotion reducedMotion) { + this.reducedMotion = reducedMotion; + return this; + } public NewPageOptions setScreenSize(int width, int height) { return setScreenSize(new ScreenSize(width, height)); } diff --git a/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java b/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java index 146e6382..804ba882 100644 --- a/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java +++ b/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java @@ -412,7 +412,7 @@ public interface BrowserContext extends AutoCloseable { * *
See {@link Page#exposeFunction Page.exposeFunction()} for page-only version. * - *
An example of adding an {@code md5} function to all pages in the context: + *
An example of adding a {@code sha256} function to all pages in the context: *
{@code
* import com.microsoft.playwright.*;
*
@@ -426,11 +426,11 @@ public interface BrowserContext extends AutoCloseable {
* try (Playwright playwright = Playwright.create()) {
* BrowserType webkit = playwright.webkit()
* Browser browser = webkit.launch(new BrowserType.LaunchOptions().setHeadless(false));
- * context.exposeFunction("sha1", args -> {
+ * context.exposeFunction("sha256", args -> {
* String text = (String) args[0];
* MessageDigest crypto;
* try {
- * crypto = MessageDigest.getInstance("SHA-1");
+ * crypto = MessageDigest.getInstance("SHA-256");
* } catch (NoSuchAlgorithmException e) {
* return null;
* }
@@ -440,7 +440,7 @@ public interface BrowserContext extends AutoCloseable {
* Page page = context.newPage();
* page.setContent("\n" +
* "\n" +
diff --git a/playwright/src/main/java/com/microsoft/playwright/BrowserType.java b/playwright/src/main/java/com/microsoft/playwright/BrowserType.java
index 20c68c97..09ebfde4 100644
--- a/playwright/src/main/java/com/microsoft/playwright/BrowserType.java
+++ b/playwright/src/main/java/com/microsoft/playwright/BrowserType.java
@@ -106,10 +106,11 @@ public interface BrowserType {
*/
public List args;
/**
- * Browser distribution channel. Read more about using Google Chrome and Microsoft Edge.
*/
- public BrowserChannel channel;
+ public Object channel;
/**
* Enable Chromium sandboxing. Defaults to {@code false}.
*/
@@ -184,16 +185,21 @@ public interface BrowserType {
/**
* If specified, traces are saved into this directory.
*/
- public Path traceDir;
+ public Path tracesDir;
public LaunchOptions setArgs(List args) {
this.args = args;
return this;
}
+ @Deprecated
public LaunchOptions setChannel(BrowserChannel channel) {
this.channel = channel;
return this;
}
+ public LaunchOptions setChannel(String channel) {
+ this.channel = channel;
+ return this;
+ }
public LaunchOptions setChromiumSandbox(boolean chromiumSandbox) {
this.chromiumSandbox = chromiumSandbox;
return this;
@@ -257,8 +263,8 @@ public interface BrowserType {
this.timeout = timeout;
return this;
}
- public LaunchOptions setTraceDir(Path traceDir) {
- this.traceDir = traceDir;
+ public LaunchOptions setTracesDir(Path tracesDir) {
+ this.tracesDir = tracesDir;
return this;
}
}
@@ -277,10 +283,11 @@ public interface BrowserType {
*/
public Boolean bypassCSP;
/**
- * Browser distribution channel. Read more about using Google Chrome and Microsoft Edge.
*/
- public BrowserChannel channel;
+ public Object channel;
/**
* Enable Chromium sandboxing. Defaults to {@code false}.
*/
@@ -408,6 +415,11 @@ public interface BrowserType {
* be scaled down if necessary to fit the specified size.
*/
public RecordVideoSize recordVideoSize;
+ /**
+ * Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}. See {@link
+ * Page#emulateMedia Page.emulateMedia()} for more details. Defaults to {@code "no-preference"}.
+ */
+ public ReducedMotion reducedMotion;
/**
* Emulates consistent window screen size available inside web page via {@code window.screen}. Is only used when the {@code viewport}
* is set.
@@ -431,7 +443,7 @@ public interface BrowserType {
/**
* If specified, traces are saved into this directory.
*/
- public Path traceDir;
+ public Path tracesDir;
/**
* Specific user agent to use in this context.
*/
@@ -453,10 +465,15 @@ public interface BrowserType {
this.bypassCSP = bypassCSP;
return this;
}
+ @Deprecated
public LaunchPersistentContextOptions setChannel(BrowserChannel channel) {
this.channel = channel;
return this;
}
+ public LaunchPersistentContextOptions setChannel(String channel) {
+ this.channel = channel;
+ return this;
+ }
public LaunchPersistentContextOptions setChromiumSandbox(boolean chromiumSandbox) {
this.chromiumSandbox = chromiumSandbox;
return this;
@@ -581,6 +598,10 @@ public interface BrowserType {
this.recordVideoSize = recordVideoSize;
return this;
}
+ public LaunchPersistentContextOptions setReducedMotion(ReducedMotion reducedMotion) {
+ this.reducedMotion = reducedMotion;
+ return this;
+ }
public LaunchPersistentContextOptions setScreenSize(int width, int height) {
return setScreenSize(new ScreenSize(width, height));
}
@@ -600,8 +621,8 @@ public interface BrowserType {
this.timezoneId = timezoneId;
return this;
}
- public LaunchPersistentContextOptions setTraceDir(Path traceDir) {
- this.traceDir = traceDir;
+ public LaunchPersistentContextOptions setTracesDir(Path tracesDir) {
+ this.tracesDir = tracesDir;
return this;
}
public LaunchPersistentContextOptions setUserAgent(String userAgent) {
diff --git a/playwright/src/main/java/com/microsoft/playwright/Page.java b/playwright/src/main/java/com/microsoft/playwright/Page.java
index 06a416ea..89c5a229 100644
--- a/playwright/src/main/java/com/microsoft/playwright/Page.java
+++ b/playwright/src/main/java/com/microsoft/playwright/Page.java
@@ -258,7 +258,8 @@ public interface Page extends AutoCloseable {
*
* NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete
* with {@link Page#onRequestFinished Page.onRequestFinished()} event and not with {@link Page#onRequestFailed
- * Page.onRequestFailed()}.
+ * Page.onRequestFailed()}. A request will only be considered failed when the client cannot get an HTTP response from the
+ * server, e.g. due to network error net::ERR_FAILED.
*/
void onRequestFailed(Consumer handler);
/**
@@ -626,6 +627,11 @@ public interface Page extends AutoCloseable {
* disables CSS media emulation.
*/
public Optional media;
+ /**
+ * Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}. Passing {@code null}
+ * disables reduced motion emulation.
+ */
+ public Optional reducedMotion;
public EmulateMediaOptions setColorScheme(ColorScheme colorScheme) {
this.colorScheme = Optional.ofNullable(colorScheme);
@@ -635,6 +641,10 @@ public interface Page extends AutoCloseable {
this.media = Optional.ofNullable(media);
return this;
}
+ public EmulateMediaOptions setReducedMotion(ReducedMotion reducedMotion) {
+ this.reducedMotion = Optional.ofNullable(reducedMotion);
+ return this;
+ }
}
class ExposeBindingOptions {
/**
@@ -1603,6 +1613,26 @@ public interface Page extends AutoCloseable {
return this;
}
}
+ class WaitForRequestFinishedOptions {
+ /**
+ * Receives the {@code Request} object and resolves to truthy value when the waiting should resolve.
+ */
+ public Predicate predicate;
+ /**
+ * Maximum time to wait for in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
+ * value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()}.
+ */
+ public Double timeout;
+
+ public WaitForRequestFinishedOptions setPredicate(Predicate predicate) {
+ this.predicate = predicate;
+ return this;
+ }
+ public WaitForRequestFinishedOptions setTimeout(double timeout) {
+ this.timeout = timeout;
+ return this;
+ }
+ }
class WaitForResponseOptions {
/**
* Maximum wait time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable the timeout. The default value can be
@@ -2508,7 +2538,7 @@ public interface Page extends AutoCloseable {
*
* NOTE: Functions installed via {@link Page#exposeFunction Page.exposeFunction()} survive navigations.
*
- *
An example of adding an {@code sha1} function to the page:
+ *
An example of adding a {@code sha256} function to the page:
*
{@code
* import com.microsoft.playwright.*;
*
@@ -2523,11 +2553,11 @@ public interface Page extends AutoCloseable {
* BrowserType webkit = playwright.webkit();
* Browser browser = webkit.launch({ headless: false });
* Page page = browser.newPage();
- * page.exposeFunction("sha1", args -> {
+ * page.exposeFunction("sha256", args -> {
* String text = (String) args[0];
* MessageDigest crypto;
* try {
- * crypto = MessageDigest.getInstance("SHA-1");
+ * crypto = MessageDigest.getInstance("SHA-256");
* } catch (NoSuchAlgorithmException e) {
* return null;
* }
@@ -2536,7 +2566,7 @@ public interface Page extends AutoCloseable {
* });
* page.setContent("\n" +
* "\n" +
@@ -4095,7 +4125,7 @@ public interface Page extends AutoCloseable {
/**
* Performs action and waits for a {@code ConsoleMessage} to be logged by in the page. If predicate is provided, it passes
* {@code ConsoleMessage} value into the {@code predicate} function and waits for {@code predicate(message)} to return a truthy value. Will
- * throw an error if the page is closed before the console event is fired.
+ * throw an error if the page is closed before the {@link Page#onConsole Page.onConsole()} event is fired.
*
* @param callback Callback that performs the action triggering the event.
*/
@@ -4105,7 +4135,7 @@ public interface Page extends AutoCloseable {
/**
* Performs action and waits for a {@code ConsoleMessage} to be logged by in the page. If predicate is provided, it passes
* {@code ConsoleMessage} value into the {@code predicate} function and waits for {@code predicate(message)} to return a truthy value. Will
- * throw an error if the page is closed before the console event is fired.
+ * throw an error if the page is closed before the {@link Page#onConsole Page.onConsole()} event is fired.
*
* @param callback Callback that performs the action triggering the event.
*/
@@ -4401,7 +4431,7 @@ public interface Page extends AutoCloseable {
* Waits for the matching request and returns it. See waiting for event for more details about events.
* {@code
- * // Waits for the next response with the specified url
+ * // Waits for the next request with the specified url
* Request request = page.waitForRequest("https://example.com/resource", () -> {
* // Triggers the request
* page.click("button.triggers-request");
@@ -4424,7 +4454,7 @@ public interface Page extends AutoCloseable {
* Waits for the matching request and returns it. See waiting for event for more details about events.
* {@code
- * // Waits for the next response with the specified url
+ * // Waits for the next request with the specified url
* Request request = page.waitForRequest("https://example.com/resource", () -> {
* // Triggers the request
* page.click("button.triggers-request");
@@ -4445,7 +4475,7 @@ public interface Page extends AutoCloseable {
* Waits for the matching request and returns it. See waiting for event for more details about events.
* {@code
- * // Waits for the next response with the specified url
+ * // Waits for the next request with the specified url
* Request request = page.waitForRequest("https://example.com/resource", () -> {
* // Triggers the request
* page.click("button.triggers-request");
@@ -4468,7 +4498,7 @@ public interface Page extends AutoCloseable {
* Waits for the matching request and returns it. See waiting for event for more details about events.
* {@code
- * // Waits for the next response with the specified url
+ * // Waits for the next request with the specified url
* Request request = page.waitForRequest("https://example.com/resource", () -> {
* // Triggers the request
* page.click("button.triggers-request");
@@ -4489,7 +4519,7 @@ public interface Page extends AutoCloseable {
* Waits for the matching request and returns it. See waiting for event for more details about events.
* {@code
- * // Waits for the next response with the specified url
+ * // Waits for the next request with the specified url
* Request request = page.waitForRequest("https://example.com/resource", () -> {
* // Triggers the request
* page.click("button.triggers-request");
@@ -4512,7 +4542,7 @@ public interface Page extends AutoCloseable {
* Waits for the matching request and returns it. See waiting for event for more details about events.
* {@code
- * // Waits for the next response with the specified url
+ * // Waits for the next request with the specified url
* Request request = page.waitForRequest("https://example.com/resource", () -> {
* // Triggers the request
* page.click("button.triggers-request");
@@ -4529,6 +4559,24 @@ public interface Page extends AutoCloseable {
* @param callback Callback that performs the action triggering the event.
*/
Request waitForRequest(Predicate urlOrPredicate, WaitForRequestOptions options, Runnable callback);
+ /**
+ * Performs action and waits for a {@code Request} to finish loading. If predicate is provided, it passes {@code Request} value into
+ * the {@code predicate} function and waits for {@code predicate(request)} to return a truthy value. Will throw an error if the page is
+ * closed before the {@link Page#onRequestFinished Page.onRequestFinished()} event is fired.
+ *
+ * @param callback Callback that performs the action triggering the event.
+ */
+ default Request waitForRequestFinished(Runnable callback) {
+ return waitForRequestFinished(null, callback);
+ }
+ /**
+ * Performs action and waits for a {@code Request} to finish loading. If predicate is provided, it passes {@code Request} value into
+ * the {@code predicate} function and waits for {@code predicate(request)} to return a truthy value. Will throw an error if the page is
+ * closed before the {@link Page#onRequestFinished Page.onRequestFinished()} event is fired.
+ *
+ * @param callback Callback that performs the action triggering the event.
+ */
+ Request waitForRequestFinished(WaitForRequestFinishedOptions options, Runnable callback);
/**
* Returns the matched response. See waiting for
* event for more details about events.
diff --git a/playwright/src/main/java/com/microsoft/playwright/Tracing.java b/playwright/src/main/java/com/microsoft/playwright/Tracing.java
index fd0fe7e8..feff48ed 100644
--- a/playwright/src/main/java/com/microsoft/playwright/Tracing.java
+++ b/playwright/src/main/java/com/microsoft/playwright/Tracing.java
@@ -25,23 +25,22 @@ import java.util.*;
*
* Start with specifying the folder traces will be stored in:
*
{@code
- * Browser browser = chromium.launch(new BrowserType.LaunchOptions().setTraceDir("trace"));
+ * Browser browser = chromium.launch();
* BrowserContext context = browser.newContext();
- * context.tracing.start(page, new Tracing.StartOptions()
- * .setName("trace")
+ * context.tracing.start(new Tracing.StartOptions()
* .setScreenshots(true)
* .setSnapshots(true);
* Page page = context.newPage();
* page.goto("https://playwright.dev");
- * context.tracing.stop();
- * context.tracing.export(Paths.get("trace.zip")))
+ * context.tracing.stop(new Tracing.StopOptions()
+ * .setPath(Paths.get("trace.zip")));
* }
*/
public interface Tracing {
class StartOptions {
/**
- * If specified, the trace is going to be saved into the file with the given name inside the {@code traceDir} folder specified in
- * {@link BrowserType#launch BrowserType.launch()}.
+ * If specified, the trace is going to be saved into the file with the given name inside the {@code tracesDir} folder specified
+ * in {@link BrowserType#launch BrowserType.launch()}.
*/
public String name;
/**
@@ -66,23 +65,27 @@ public interface Tracing {
return this;
}
}
- /**
- * Export trace into the file with the given name. Should be called after the tracing has stopped.
- *
- * @param path File to save the trace into.
- */
- void export(Path path);
+ class StopOptions {
+ /**
+ * Export trace into the file with the given name.
+ */
+ public Path path;
+
+ public StopOptions setPath(Path path) {
+ this.path = path;
+ return this;
+ }
+ }
/**
* Start tracing.
* {@code
- * context.tracing.start(page, new Tracing.StartOptions()
- * .setName("trace")
+ * context.tracing.start(new Tracing.StartOptions()
* .setScreenshots(true)
* .setSnapshots(true);
* Page page = context.newPage();
* page.goto('https://playwright.dev');
- * context.tracing.stop();
- * context.tracing.export(Paths.get("trace.zip")))
+ * context.tracing.stop(new Tracing.StopOptions()
+ * .setPath(Paths.get("trace.zip")));
* }
*/
default void start() {
@@ -91,20 +94,25 @@ public interface Tracing {
/**
* Start tracing.
* {@code
- * context.tracing.start(page, new Tracing.StartOptions()
- * .setName("trace")
+ * context.tracing.start(new Tracing.StartOptions()
* .setScreenshots(true)
* .setSnapshots(true);
* Page page = context.newPage();
* page.goto('https://playwright.dev');
- * context.tracing.stop();
- * context.tracing.export(Paths.get("trace.zip")))
+ * context.tracing.stop(new Tracing.StopOptions()
+ * .setPath(Paths.get("trace.zip")));
* }
*/
void start(StartOptions options);
/**
* Stop tracing.
*/
- void stop();
+ default void stop() {
+ stop(null);
+ }
+ /**
+ * Stop tracing.
+ */
+ void stop(StopOptions options);
}
diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java
index e8fc6392..b7257509 100644
--- a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java
+++ b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java
@@ -1299,6 +1299,24 @@ public class PageImpl extends ChannelOwner implements Page {
return runUntil(code, new WaitableRace<>(waitables));
}
+ @Override
+ public Request waitForRequestFinished(WaitForRequestFinishedOptions options, Runnable code) {
+ return withWaitLogging("Page.waitForRequestFinished", () -> waitForRequestFinishedImpl(options, code));
+ }
+
+ private Request waitForRequestFinishedImpl(WaitForRequestFinishedOptions options, Runnable code) {
+ if (options == null) {
+ options = new WaitForRequestFinishedOptions();
+ }
+ List> waitables = new ArrayList<>();
+ Predicate predicate = options.predicate;
+ waitables.add(new WaitableEvent<>(listeners, EventType.REQUESTFINISHED,
+ request -> predicate == null || predicate.test(request)));
+ waitables.add(createWaitForCloseHelper());
+ waitables.add(createWaitableTimeout(options.timeout));
+ return runUntil(code, new WaitableRace<>(waitables));
+ }
+
@Override
public Response waitForResponse(String urlGlob, WaitForResponseOptions options, Runnable code) {
return waitForResponse(toResponsePredicate(new UrlMatcher(urlGlob)), options, code);
diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/TracingImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/TracingImpl.java
index c55709c6..46716a5e 100644
--- a/playwright/src/main/java/com/microsoft/playwright/impl/TracingImpl.java
+++ b/playwright/src/main/java/com/microsoft/playwright/impl/TracingImpl.java
@@ -31,12 +31,7 @@ class TracingImpl implements Tracing {
this.context = context;
}
- @Override
- public void export(Path path) {
- context.withLogging("Tracing.export", () -> exportImpl(path));
- }
-
- private void exportImpl(Path path) {
+ private void export(Path path) {
JsonObject json = context.sendMessage("tracingExport").getAsJsonObject();
ArtifactImpl artifact = context.connection.getExistingObject(json.getAsJsonObject("artifact").get("guid").getAsString());
if (context.browser().isRemote) {
@@ -60,7 +55,12 @@ class TracingImpl implements Tracing {
}
@Override
- public void stop() {
- context.withLogging("Tracing.stop", () -> context.sendMessage("tracingStop"));
+ public void stop(StopOptions options) {
+ context.withLogging("Tracing.stop", () -> {
+ context.sendMessage("tracingStop");
+ if (options != null && options.path != null) {
+ export(options.path);
+ }
+ });
}
}
diff --git a/playwright/src/main/java/com/microsoft/playwright/options/BrowserChannel.java b/playwright/src/main/java/com/microsoft/playwright/options/BrowserChannel.java
index 5b104618..3743c614 100644
--- a/playwright/src/main/java/com/microsoft/playwright/options/BrowserChannel.java
+++ b/playwright/src/main/java/com/microsoft/playwright/options/BrowserChannel.java
@@ -16,6 +16,7 @@
package com.microsoft.playwright.options;
+@Deprecated
public enum BrowserChannel {
CHROME,
CHROME_BETA,
@@ -26,4 +27,4 @@ public enum BrowserChannel {
MSEDGE_DEV,
MSEDGE_CANARY,
@Deprecated FIREFOX_STABLE
-}
\ No newline at end of file
+}
diff --git a/playwright/src/main/java/com/microsoft/playwright/options/ReducedMotion.java b/playwright/src/main/java/com/microsoft/playwright/options/ReducedMotion.java
new file mode 100644
index 00000000..45c94cf4
--- /dev/null
+++ b/playwright/src/main/java/com/microsoft/playwright/options/ReducedMotion.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.microsoft.playwright.options;
+
+public enum ReducedMotion {
+ REDUCE,
+ NO_PREFERENCE
+}
\ No newline at end of file
diff --git a/playwright/src/test/java/com/microsoft/playwright/TestBase.java b/playwright/src/test/java/com/microsoft/playwright/TestBase.java
index a67aadba..f6ca80c6 100644
--- a/playwright/src/test/java/com/microsoft/playwright/TestBase.java
+++ b/playwright/src/test/java/com/microsoft/playwright/TestBase.java
@@ -61,22 +61,8 @@ public class TestBase {
return "firefox".equals(getBrowserNameFromEnv());
}
- static BrowserChannel getBrowserChannelFromEnv() {
- String channel = System.getenv("BROWSER_CHANNEL");
- if (channel == null) {
- return null;
- }
- switch (channel) {
- case "chrome": return BrowserChannel.CHROME;
- case "chrome-beta": return BrowserChannel.CHROME_BETA;
- case "chrome-dev": return BrowserChannel.CHROME_DEV;
- case "chrome-canary": return BrowserChannel.CHROME_CANARY;
- case "msedge": return BrowserChannel.MSEDGE;
- case "msedge-beta": return BrowserChannel.MSEDGE_BETA;
- case "msedge-dev": return BrowserChannel.MSEDGE_DEV;
- case "msedge-canary": return BrowserChannel.MSEDGE_CANARY;
- default: throw new IllegalArgumentException("Unknown BROWSER_CHANNEL " + channel);
- }
+ static String getBrowserChannelFromEnv() {
+ return System.getenv("BROWSER_CHANNEL");
}
static BrowserType.LaunchOptions createLaunchOptions() {
diff --git a/playwright/src/test/java/com/microsoft/playwright/TestBrowser.java b/playwright/src/test/java/com/microsoft/playwright/TestBrowser.java
index 19e61967..ac466fd3 100644
--- a/playwright/src/test/java/com/microsoft/playwright/TestBrowser.java
+++ b/playwright/src/test/java/com/microsoft/playwright/TestBrowser.java
@@ -16,6 +16,8 @@
package com.microsoft.playwright;
+import com.microsoft.playwright.options.BrowserChannel;
+import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
import java.util.regex.Pattern;
@@ -66,4 +68,33 @@ public class TestBrowser extends TestBase {
assertTrue(Pattern.matches("^\\d+\\.\\d+.*", browser.version()));
}
}
+
+ private static BrowserChannel getBrowserChannelEnumFromEnv() {
+ String channel = getBrowserChannelFromEnv();
+ if (channel == null) {
+ return null;
+ }
+ switch (channel) {
+ case "chrome": return BrowserChannel.CHROME;
+ case "chrome-beta": return BrowserChannel.CHROME_BETA;
+ case "chrome-dev": return BrowserChannel.CHROME_DEV;
+ case "chrome-canary": return BrowserChannel.CHROME_CANARY;
+ case "msedge": return BrowserChannel.MSEDGE;
+ case "msedge-beta": return BrowserChannel.MSEDGE_BETA;
+ case "msedge-dev": return BrowserChannel.MSEDGE_DEV;
+ case "msedge-canary": return BrowserChannel.MSEDGE_CANARY;
+ default: throw new IllegalArgumentException("Unknown BROWSER_CHANNEL " + channel);
+ }
+ }
+
+ @Test
+ void shouldSupportDeprecatedChannelEnum() {
+ BrowserChannel channel = getBrowserChannelEnumFromEnv();
+ Assumptions.assumeTrue(channel != null);
+ BrowserType.LaunchOptions options = createLaunchOptions();
+ options.setChannel(channel);
+ Browser browser = browserType.launch(options);
+ assertNotNull(browser);
+ browser.close();
+ }
}
diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageEventNetwork.java b/playwright/src/test/java/com/microsoft/playwright/TestPageEventNetwork.java
index cd4fb0c1..6834ff65 100644
--- a/playwright/src/test/java/com/microsoft/playwright/TestPageEventNetwork.java
+++ b/playwright/src/test/java/com/microsoft/playwright/TestPageEventNetwork.java
@@ -81,9 +81,28 @@ public class TestPageEventNetwork extends TestBase {
Request[] requestRef = {null};
page.onRequestFinished(r -> requestRef[0] = r);
Response response = page.navigate(server.EMPTY_PAGE);
- assertNull(response.finished());
assertNotNull(response);
+ assertNull(response.finished());
Request request = requestRef[0];
+ assertNotNull(request);
+ assertEquals(response.request(), request);
+ assertEquals(server.EMPTY_PAGE, request.url());
+ assertNotNull(request.response());
+ assertEquals(page.mainFrame(), request.frame());
+ assertEquals(server.EMPTY_PAGE, request.frame().url());
+ assertNull(request.failure());
+ }
+
+ @Test
+ void PageWaitForRequestFinished() {
+ Response[] responseRef = {null};
+ Request request = page.waitForRequestFinished(() -> {
+ responseRef[0] = page.navigate(server.EMPTY_PAGE);
+ });
+ assertNotNull(request);
+ Response response = responseRef[0];
+ assertNotNull(response);
+ assertNull(response.finished());
assertEquals(response.request(), request);
assertEquals(server.EMPTY_PAGE, request.url());
assertNotNull(request.response());
diff --git a/playwright/src/test/java/com/microsoft/playwright/TestTracing.java b/playwright/src/test/java/com/microsoft/playwright/TestTracing.java
index d3864ffc..cba5101d 100644
--- a/playwright/src/test/java/com/microsoft/playwright/TestTracing.java
+++ b/playwright/src/test/java/com/microsoft/playwright/TestTracing.java
@@ -38,7 +38,7 @@ public class TestTracing extends TestBase {
void launchBrowser(@TempDir Path tempDir) {
System.out.println("new launchBrowser(");
BrowserType.LaunchOptions options = createLaunchOptions();
- options.setTraceDir(tempDir.resolve("trace-dir"));
+ options.setTracesDir(tempDir.resolve("trace-dir"));
launchBrowser(options);
}
@@ -50,9 +50,8 @@ public class TestTracing extends TestBase {
page.setContent("");
page.click("'Click'");
page.close();
- context.tracing().stop();
Path traceFile = tempDir.resolve("trace.zip");
- context.tracing().export(traceFile);
+ context.tracing().stop(new Tracing.StopOptions().setPath(traceFile));
assertTrue(Files.exists(traceFile));
}
@@ -64,17 +63,15 @@ public class TestTracing extends TestBase {
page.navigate(server.EMPTY_PAGE);
page.setContent("");
page.click("'Click'");
- context.tracing().stop();
Path traceFile1 = tempDir.resolve("trace1.zip");
- context.tracing().export(traceFile1);
+ context.tracing().stop(new Tracing.StopOptions().setPath(traceFile1));
context.tracing().start(new Tracing.StartOptions().setName("test2")
.setScreenshots(true).setSnapshots(true));
page.dblclick("'Click'");
page.close();
- context.tracing().stop();
Path traceFile2 = tempDir.resolve("trace2.zip");
- context.tracing().export(traceFile2);
+ context.tracing().stop(new Tracing.StopOptions().setPath(traceFile2));
assertTrue(Files.exists(traceFile1));
assertTrue(Files.exists(traceFile2));
diff --git a/scripts/CLI_VERSION b/scripts/CLI_VERSION
index f4163aff..66fcd511 100644
--- a/scripts/CLI_VERSION
+++ b/scripts/CLI_VERSION
@@ -1 +1 @@
-1.12.0-next-1621527598000
+1.12.0-next-1622765855000
diff --git a/tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java b/tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java
index 8a109649..55433dfd 100644
--- a/tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java
+++ b/tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java
@@ -761,6 +761,9 @@ class Field extends Element {
typeStr = "Boolean";
}
}
+ if (isBrowserChannelOption()) {
+ typeStr = "Object";
+ }
output.add(offset + "public " + typeStr + " " + name + ";");
}
@@ -791,6 +794,12 @@ class Field extends Element {
}
}
}
+
+ if (isBrowserChannelOption()) {
+ output.add(offset + "@Deprecated");
+ writeGenericBuilderMethod(output, offset, parentClass, "BrowserChannel");
+ }
+
writeGenericBuilderMethod(output, offset, parentClass, type.toJava());
}
@@ -801,6 +810,10 @@ class Field extends Element {
output.add(offset + " return this;");
output.add(offset + "}");
}
+
+ private boolean isBrowserChannelOption() {
+ return asList("BrowserType.launch.options.channel", "BrowserType.launchPersistentContext.options.channel").contains(jsonPath);
+ }
}
class Interface extends TypeDefinition {