Skip to content
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->113.0.5672.24<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Chromium <!-- GEN:chromium-version -->113.0.5672.53<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| WebKit <!-- GEN:webkit-version -->16.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->111.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Firefox <!-- GEN:firefox-version -->112.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |

Headless execution is supported for all the browsers on all platforms. Check out [system requirements](https://playwright.dev/java/docs/next/intro/#system-requirements) for details.

Expand Down
110 changes: 70 additions & 40 deletions playwright/src/main/java/com/microsoft/playwright/Browser.java

Large diffs are not rendered by default.

55 changes: 35 additions & 20 deletions playwright/src/main/java/com/microsoft/playwright/BrowserType.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ class LaunchPersistentContextOptions {
*/
public Optional<ColorScheme> colorScheme;
/**
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
*/
public Double deviceScaleFactor;
/**
Expand Down Expand Up @@ -462,7 +463,8 @@ class LaunchPersistentContextOptions {
*/
public Boolean handleSIGTERM;
/**
* Specifies if viewport supports touch events. Defaults to false.
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
*/
public Boolean hasTouch;
/**
Expand Down Expand Up @@ -492,21 +494,25 @@ class LaunchPersistentContextOptions {
*/
public Boolean ignoreHTTPSErrors;
/**
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
* supported in Firefox.
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
* about <a href="https://playwright.dev/java/docs/emulation#isMobile">mobile emulation</a>.
*/
public Boolean isMobile;
/**
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
*/
public Boolean javaScriptEnabled;
/**
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
* {@code Accept-Language} request header value as well as number and date formatting rules.
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
*/
public String locale;
/**
* Whether to emulate network being offline. Defaults to {@code false}.
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
*/
public Boolean offline;
/**
Expand Down Expand Up @@ -602,8 +608,9 @@ class LaunchPersistentContextOptions {
*/
public String userAgent;
/**
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
* viewport emulation.
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
* consistent viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
* emulation</a>.
*
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
* operating system. It makes the execution of the tests non-deterministic.
Expand Down Expand Up @@ -687,7 +694,8 @@ public LaunchPersistentContextOptions setColorScheme(ColorScheme colorScheme) {
return this;
}
/**
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
*/
public LaunchPersistentContextOptions setDeviceScaleFactor(double deviceScaleFactor) {
this.deviceScaleFactor = deviceScaleFactor;
Expand Down Expand Up @@ -771,7 +779,8 @@ public LaunchPersistentContextOptions setHandleSIGTERM(boolean handleSIGTERM) {
return this;
}
/**
* Specifies if viewport supports touch events. Defaults to false.
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
*/
public LaunchPersistentContextOptions setHasTouch(boolean hasTouch) {
this.hasTouch = hasTouch;
Expand Down Expand Up @@ -826,30 +835,34 @@ public LaunchPersistentContextOptions setIgnoreHTTPSErrors(boolean ignoreHTTPSEr
return this;
}
/**
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
* supported in Firefox.
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
* about <a href="https://playwright.dev/java/docs/emulation#isMobile">mobile emulation</a>.
*/
public LaunchPersistentContextOptions setIsMobile(boolean isMobile) {
this.isMobile = isMobile;
return this;
}
/**
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
*/
public LaunchPersistentContextOptions setJavaScriptEnabled(boolean javaScriptEnabled) {
this.javaScriptEnabled = javaScriptEnabled;
return this;
}
/**
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
* {@code Accept-Language} request header value as well as number and date formatting rules.
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
*/
public LaunchPersistentContextOptions setLocale(String locale) {
this.locale = locale;
return this;
}
/**
* Whether to emulate network being offline. Defaults to {@code false}.
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
*/
public LaunchPersistentContextOptions setOffline(boolean offline) {
this.offline = offline;
Expand Down Expand Up @@ -1027,8 +1040,9 @@ public LaunchPersistentContextOptions setUserAgent(String userAgent) {
return this;
}
/**
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
* viewport emulation.
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
* consistent viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
* emulation</a>.
*
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
* operating system. It makes the execution of the tests non-deterministic.
Expand All @@ -1037,8 +1051,9 @@ public LaunchPersistentContextOptions setViewportSize(int width, int height) {
return setViewportSize(new ViewportSize(width, height));
}
/**
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
* viewport emulation.
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
* consistent viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
* emulation</a>.
*
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
* operating system. It makes the execution of the tests non-deterministic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2020,9 +2020,10 @@ public WaitForOptions setTimeout(double timeout) {
/**
* When locator points to a list of elements, returns array of locators, pointing to respective elements.
*
* <p> Note that {@link Locator#all Locator.all()} does not wait for elements to match the locator, and instead immediately
* returns whatever is present in the page. To avoid flakiness when elements are loaded dynamically, wait for the loading
* to finish before calling {@link Locator#all Locator.all()}.
* <p> <strong>NOTE:</strong> {@link Locator#all Locator.all()} does not wait for elements to match the locator, and instead immediately returns
* whatever is present in the page. When the list of elements changes dynamically, {@link Locator#all Locator.all()} will
* produce unpredictable and flaky results. When the list of elements is stable, but loaded dynamically, wait for the full
* list to finish loading before calling {@link Locator#all Locator.all()}.
*
* <p> **Usage**
* <pre>{@code
Expand Down
11 changes: 11 additions & 0 deletions playwright/src/main/java/com/microsoft/playwright/Route.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ class FetchOptions {
* If set changes the post data of request.
*/
public Object postData;
/**
* Request timeout in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout.
*/
public Double timeout;
/**
* If set changes the request URL. New URL must have same protocol as original one.
*/
Expand Down Expand Up @@ -195,6 +199,13 @@ public FetchOptions setPostData(byte[] postData) {
this.postData = postData;
return this;
}
/**
* Request timeout in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout.
*/
public FetchOptions setTimeout(double timeout) {
this.timeout = timeout;
return this;
}
/**
* If set changes the request URL. New URL must have same protocol as original one.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public APIResponse fetch(FetchOptions fetchOptions) {
} else {
options.data = request.postDataBuffer();
}
if (fetchOptions != null && fetchOptions.timeout != null) {
options.timeout = fetchOptions.timeout;
}
APIRequestContextImpl apiRequest = request.frame().page().context().request();
String url = (fetchOptions == null || fetchOptions.url == null) ? request().url() : fetchOptions.url;
return apiRequest.fetch(url, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static void writeToFile(byte[] buffer, Path path) {
static void writeToFile(InputStream inputStream, Path path) {
mkParentDirs(path);
try (FileOutputStream out = new FileOutputStream(path.toFile())) {
byte[] buf = new byte[8192];
byte[] buf = new byte[1024 * 1024];
int length;
while ((length = inputStream.read(buf)) > 0) {
out.write(buf, 0, length);
Expand Down
17 changes: 11 additions & 6 deletions playwright/src/test/java/com/microsoft/playwright/TestClick.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@

package com.microsoft.playwright;

import com.microsoft.playwright.options.AriaRole;
import com.microsoft.playwright.options.WaitUntilState;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;
import org.junit.jupiter.api.condition.EnabledIf;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

import static com.microsoft.playwright.options.KeyboardModifier.SHIFT;
import static com.microsoft.playwright.options.MouseButton.RIGHT;
Expand Down Expand Up @@ -425,15 +422,23 @@ void shouldClickTheButtonWithOffsetWithPageScale() {
// 20;10 + 8px of border in each direction
int expectedX = 28;
int expectedY = 18;

if (isWebKit()) {
// WebKit rounds up during css -> dip -> css conversion.
expectedX = 26;
expectedY = 17;
// WebKit for macOS 12 has different expectations starting r1829.
if (isMac && Utils.osVersion() < 12) {
// WebKit rounds up during css -> dip -> css conversion.
expectedX = 26;
expectedY = 17;
} else {
expectedX = 29;
expectedY = 19;
}
} else if (isChromium() && !headful) {
// Headless Chromium rounds down during css -> dip -> css conversion.
expectedX = 27;
expectedY = 18;
}

assertEquals(expectedX, Math.round((Integer) page.evaluate("pageX") + 0.01));
assertEquals(expectedY, Math.round((Integer) page.evaluate("pageY") + 0.01));
context.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.junit.jupiter.api.Test;

import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -71,6 +73,23 @@ void shouldFulfillInterceptedResponseUsingAlias() {
assertTrue(response.headers().get("content-type").contains("text/html"));
}

@Test
void shouldSupportTimeoutOptionInRouteFetch() {
server.setRoute("/slow", exchange -> {
exchange.getResponseHeaders().set("Content-type", "text/plain");
exchange.sendResponseHeaders(200, 4096);
});

page.route("**/*", route -> {
PlaywrightException error = assertThrows(PlaywrightException.class,
() -> route.fetch(new Route.FetchOptions().setTimeout(1000)));
assertTrue(error.getMessage().contains("Request timed out after 1000ms"), error.getMessage());
});
PlaywrightException error = assertThrows(PlaywrightException.class,
() -> page.navigate(server.PREFIX + "/slow", new Page.NavigateOptions().setTimeout(2000)));
assertTrue(error.getMessage().contains("Timeout 2000ms exceeded"), error.getMessage());
}

@Test
void shouldInterceptWithUrlOverride() {
page.route("**/*.html", route -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void shouldRejectFutureEventOnSocketClose() {
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
ws.waitForFrameSent(() -> page.evaluate("window.ws.close()"));
});
assertTrue(e.getMessage().contains("Socket closed"), e.getMessage());
assertTrue(e.getMessage().matches("Socket closed|Socket error"), e.getMessage());
}

@Test
Expand Down
4 changes: 4 additions & 0 deletions playwright/src/test/java/com/microsoft/playwright/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ static OS getOS() {
return OS.UNKNOWN;
}

static int osVersion() {
return Integer.parseInt(System.getProperty("os.version").split("\\.")[0]);
}

static List<String> expectedSSLError(String browserName) {
switch (browserName) {
case "chromium":
Expand Down
2 changes: 1 addition & 1 deletion scripts/CLI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.33.0-alpha-apr-12-2023
1.33.0-beta-1682447195000