diff --git a/README.md b/README.md index e60fe747..ddbf5d93 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom | | Linux | macOS | Windows | | :--- | :---: | :---: | :---: | -| Chromium 115.0.5790.75 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| Chromium 116.0.5845.82 | :white_check_mark: | :white_check_mark: | :white_check_mark: | | WebKit 17.0 | ✅ | ✅ | ✅ | | Firefox 115.0 | :white_check_mark: | :white_check_mark: | :white_check_mark: | diff --git a/playwright/src/main/java/com/microsoft/playwright/Browser.java b/playwright/src/main/java/com/microsoft/playwright/Browser.java index b4a8a84b..a93f98f5 100644 --- a/playwright/src/main/java/com/microsoft/playwright/Browser.java +++ b/playwright/src/main/java/com/microsoft/playwright/Browser.java @@ -120,7 +120,7 @@ public interface Browser extends AutoCloseable { /** * 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 mobile emulation. + * about mobile emulation. */ public Boolean isMobile; /** @@ -236,8 +236,8 @@ public interface Browser extends AutoCloseable { */ public String userAgent; /** - * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the - * consistent viewport emulation. Learn more about viewport + * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent + * viewport emulation. Learn more about viewport * emulation. * *
NOTE: The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the @@ -351,7 +351,7 @@ public interface Browser extends AutoCloseable { /** * 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 mobile emulation. + * about mobile emulation. */ public NewContextOptions setIsMobile(boolean isMobile) { this.isMobile = isMobile; @@ -559,8 +559,8 @@ public interface Browser extends AutoCloseable { return this; } /** - * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the - * consistent viewport emulation. Learn more about viewport + * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent + * viewport emulation. Learn more about viewport * emulation. * *
NOTE: The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the @@ -570,8 +570,8 @@ public interface Browser extends AutoCloseable { 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. Learn more about viewport + * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent + * viewport emulation. Learn more about viewport * emulation. * *
NOTE: The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the @@ -646,7 +646,7 @@ public interface Browser extends AutoCloseable { /** * 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 mobile emulation. + * about mobile emulation. */ public Boolean isMobile; /** @@ -762,8 +762,8 @@ public interface Browser extends AutoCloseable { */ public String userAgent; /** - * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the - * consistent viewport emulation. Learn more about viewport + * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent + * viewport emulation. Learn more about viewport * emulation. * *
NOTE: The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the @@ -877,7 +877,7 @@ public interface Browser extends AutoCloseable { /** * 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 mobile emulation. + * about mobile emulation. */ public NewPageOptions setIsMobile(boolean isMobile) { this.isMobile = isMobile; @@ -1085,8 +1085,8 @@ public interface Browser extends AutoCloseable { return this; } /** - * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the - * consistent viewport emulation. Learn more about viewport + * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent + * viewport emulation. Learn more about viewport * emulation. * *
NOTE: The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the @@ -1096,8 +1096,8 @@ public interface Browser extends AutoCloseable { 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. Learn more about viewport + * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent + * viewport emulation. Learn more about viewport * emulation. * *
NOTE: The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
diff --git a/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java b/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java
index 74378506..35338811 100644
--- a/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java
+++ b/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java
@@ -1116,7 +1116,7 @@ public interface BrowserContext extends AutoCloseable {
void route(Predicate Playwright will not serve requests intercepted by Service Worker from the HAR file. See this issue. We recommend disabling Service Workers when
@@ -1131,7 +1131,7 @@ public interface BrowserContext extends AutoCloseable {
}
/**
* If specified the network requests that are made in the context will be served from the HAR file. Read more about Replaying from HAR.
+ * href="https://playwright.dev/java/docs/mock#replaying-from-har">Replaying from HAR.
*
* Playwright will not serve requests intercepted by Service Worker from the HAR file. See this issue. We recommend disabling Service Workers when
diff --git a/playwright/src/main/java/com/microsoft/playwright/BrowserType.java b/playwright/src/main/java/com/microsoft/playwright/BrowserType.java
index 6983b3a6..b94888bd 100644
--- a/playwright/src/main/java/com/microsoft/playwright/BrowserType.java
+++ b/playwright/src/main/java/com/microsoft/playwright/BrowserType.java
@@ -43,6 +43,26 @@ import java.util.regex.Pattern;
*/
public interface BrowserType {
class ConnectOptions {
+ /**
+ * This option exposes network available on the connecting client to the browser being connected to. Consists of a list of
+ * rules separated by comma.
+ *
+ * Available rules:
+ * Some common examples:
+ * Available rules:
+ * Some common examples:
+ * NOTE: The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
@@ -839,7 +882,7 @@ public interface BrowserType {
/**
* 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 mobile emulation.
+ * about mobile emulation.
*/
public LaunchPersistentContextOptions setIsMobile(boolean isMobile) {
this.isMobile = isMobile;
@@ -1044,8 +1087,8 @@ public interface BrowserType {
return this;
}
/**
- * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
- * consistent viewport emulation. Learn more about viewport
+ * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
+ * viewport emulation. Learn more about viewport
* emulation.
*
* NOTE: The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
@@ -1055,8 +1098,8 @@ public interface BrowserType {
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. Learn more about viewport
+ * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
+ * viewport emulation. Learn more about viewport
* emulation.
*
* NOTE: The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
diff --git a/playwright/src/main/java/com/microsoft/playwright/Frame.java b/playwright/src/main/java/com/microsoft/playwright/Frame.java
index bd3faada..a153b96e 100644
--- a/playwright/src/main/java/com/microsoft/playwright/Frame.java
+++ b/playwright/src/main/java/com/microsoft/playwright/Frame.java
@@ -4473,7 +4473,9 @@ public interface Frame {
*/
void setChecked(String selector, boolean checked, SetCheckedOptions options);
/**
- *
+ * This method internally calls document.write(), inheriting all its specific
+ * characteristics and behaviors.
*
* @param html HTML markup to assign to the page.
* @since v1.8
@@ -4482,7 +4484,9 @@ public interface Frame {
setContent(html, null);
}
/**
- *
+ * This method internally calls document.write(), inheriting all its specific
+ * characteristics and behaviors.
*
* @param html HTML markup to assign to the page.
* @since v1.8
diff --git a/playwright/src/main/java/com/microsoft/playwright/Locator.java b/playwright/src/main/java/com/microsoft/playwright/Locator.java
index e106f465..1060d382 100644
--- a/playwright/src/main/java/com/microsoft/playwright/Locator.java
+++ b/playwright/src/main/java/com/microsoft/playwright/Locator.java
@@ -23,7 +23,7 @@ import java.util.regex.Pattern;
/**
* Locators are the central piece of Playwright's auto-waiting and retry-ability. In a nutshell, locators represent a way
- * to find element(s) on the page at any moment. Locator can be created with the {@link Page#locator Page.locator()}
+ * to find element(s) on the page at any moment. A locator can be created with the {@link Page#locator Page.locator()}
* method.
*
* Learn more about locators.
@@ -2033,7 +2033,7 @@ public interface Locator {
}
}
/**
- * When locator points to a list of elements, returns array of locators, pointing to respective elements.
+ * When the locator points to a list of elements, this returns an array of locators, pointing to their respective elements.
*
* NOTE: {@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
@@ -4865,7 +4865,10 @@ public interface Locator {
*/
String textContent(TextContentOptions options);
/**
- * Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
+ * NOTE: In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to type characters if there is
+ * special keyboard handling on the page.
+ *
+ * Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
* character in the text.
*
* To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Locator#press Locator.press()}.
@@ -4890,7 +4893,10 @@ public interface Locator {
type(text, null);
}
/**
- * Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
+ * NOTE: In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to type characters if there is
+ * special keyboard handling on the page.
+ *
+ * Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
* character in the text.
*
* To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Locator#press Locator.press()}.
diff --git a/playwright/src/main/java/com/microsoft/playwright/Page.java b/playwright/src/main/java/com/microsoft/playwright/Page.java
index ca4598c8..dfff3ed8 100644
--- a/playwright/src/main/java/com/microsoft/playwright/Page.java
+++ b/playwright/src/main/java/com/microsoft/playwright/Page.java
@@ -6201,7 +6201,7 @@ public interface Page extends AutoCloseable {
void route(Predicate Playwright will not serve requests intercepted by Service Worker from the HAR file. See this issue. We recommend disabling Service Workers when
@@ -6216,7 +6216,7 @@ public interface Page extends AutoCloseable {
}
/**
* If specified the network requests that are made in the page will be served from the HAR file. Read more about Replaying from HAR.
+ * href="https://playwright.dev/java/docs/mock#replaying-from-har">Replaying from HAR.
*
* Playwright will not serve requests intercepted by Service Worker from the HAR file. See this issue. We recommend disabling Service Workers when
@@ -6672,7 +6672,9 @@ public interface Page extends AutoCloseable {
*/
void setChecked(String selector, boolean checked, SetCheckedOptions options);
/**
- *
+ * This method internally calls document.write(), inheriting all its specific
+ * characteristics and behaviors.
*
* @param html HTML markup to assign to the page.
* @since v1.8
@@ -6681,7 +6683,9 @@ public interface Page extends AutoCloseable {
setContent(html, null);
}
/**
- *
+ * This method internally calls document.write(), inheriting all its specific
+ * characteristics and behaviors.
*
* @param html HTML markup to assign to the page.
* @since v1.8
diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/ArtifactImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/ArtifactImpl.java
index 2aa98bd4..aab984c2 100644
--- a/playwright/src/main/java/com/microsoft/playwright/impl/ArtifactImpl.java
+++ b/playwright/src/main/java/com/microsoft/playwright/impl/ArtifactImpl.java
@@ -19,6 +19,8 @@ package com.microsoft.playwright.impl;
import com.google.gson.JsonObject;
import com.microsoft.playwright.PlaywrightException;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.nio.file.FileSystems;
import java.nio.file.Path;
@@ -39,6 +41,20 @@ class ArtifactImpl extends ChannelOwner {
return stream.stream();
}
+ byte[] readAllBytes() {
+ final int bufLen = 1024 * 1024;
+ byte[] buf = new byte[bufLen];
+ int readLen;
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); InputStream stream = createReadStream()) {
+ while ((readLen = stream.read(buf, 0, bufLen)) != -1) {
+ outputStream.write(buf, 0, readLen);
+ }
+ return outputStream.toByteArray();
+ } catch (IOException e) {
+ throw new PlaywrightException("Failed to read artifact", e);
+ }
+ }
+
public void cancel() {
sendMessage("cancel");
}
diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/BrowserImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/BrowserImpl.java
index e630f9ba..e13368e9 100644
--- a/playwright/src/main/java/com/microsoft/playwright/impl/BrowserImpl.java
+++ b/playwright/src/main/java/com/microsoft/playwright/impl/BrowserImpl.java
@@ -28,7 +28,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.function.Consumer;
-import java.util.regex.Pattern;
import static com.microsoft.playwright.impl.Serialization.addHarUrlFilter;
import static com.microsoft.playwright.impl.Serialization.gson;
@@ -42,6 +41,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
private boolean isConnected = true;
BrowserTypeImpl browserType;
BrowserType.LaunchOptions launchOptions;
+ private Path tracePath;
enum EventType {
DISCONNECTED,
@@ -231,6 +231,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
if (options == null) {
options = new StartTracingOptions();
}
+ tracePath = options.path;
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
if (page != null) {
params.add("page", ((PageImpl) page).toProtocolRef());
@@ -245,7 +246,20 @@ class BrowserImpl extends ChannelOwner implements Browser {
private byte[] stopTracingImpl() {
JsonObject json = sendMessage("stopTracing").getAsJsonObject();
- return Base64.getDecoder().decode(json.get("binary").getAsString());
+ ArtifactImpl artifact = connection.getExistingObject(json.getAsJsonObject().getAsJsonObject("artifact").get("guid").getAsString());
+ byte[] data = artifact.readAllBytes();
+ artifact.delete();
+ if (tracePath != null) {
+ try {
+ Files.createDirectories(tracePath.getParent());
+ Files.write(tracePath, data);
+ } catch (IOException e) {
+ throw new PlaywrightException("Failed to write trace file", e);
+ } finally {
+ tracePath = null;
+ }
+ }
+ return data;
}
private Page newPageImpl(NewPageOptions options) {
diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java
index 3cf829fa..c507d50c 100644
--- a/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java
+++ b/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java
@@ -407,7 +407,7 @@ class LocatorImpl implements Locator {
if (other.frame != frame) {
throw new PlaywrightException("Locators must belong to the same frame.");
}
- return locator(other.selector, options);
+ return new LocatorImpl(frame, this.selector + " >> internal:chain=" + gson().toJson(other.selector), options);
}
@Override
diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java b/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java
index 84f774c8..717904fe 100644
--- a/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java
+++ b/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java
@@ -128,6 +128,12 @@ class Utils {
case '?':
tokens.append('.');
break;
+ case '[':
+ tokens.append('[');
+ break;
+ case ']':
+ tokens.append(']');
+ break;
case '{':
inGroup = true;
tokens.append('(');
diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageInterception.java b/playwright/src/test/java/com/microsoft/playwright/TestPageInterception.java
index 0df221f8..376fe77e 100644
--- a/playwright/src/test/java/com/microsoft/playwright/TestPageInterception.java
+++ b/playwright/src/test/java/com/microsoft/playwright/TestPageInterception.java
@@ -124,4 +124,15 @@ public class TestPageInterception extends TestBase {
page.navigate(server.PREFIX + "/foo");
assertTrue(page.content().contains("hello"));
}
+
+ @Test
+ void shouldProperlyHandleCharacterSetsInGlobs() {
+ page.route("**/[a-z]*.html", route -> {
+ APIResponse response = route.fetch(new Route.FetchOptions().setUrl(server.PREFIX + "/one-style.html"));
+ route.fulfill(new Route.FulfillOptions().setResponse(response));
+ });
+ Response response = page.navigate(server.PREFIX + "/empty.html");
+ assertEquals(200, response.status());
+ assertTrue(response.text().contains("one-style.css"), response.text());
+ }
}
diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageLocatorQuery.java b/playwright/src/test/java/com/microsoft/playwright/TestPageLocatorQuery.java
index 1328d985..30581c07 100644
--- a/playwright/src/test/java/com/microsoft/playwright/TestPageLocatorQuery.java
+++ b/playwright/src/test/java/com/microsoft/playwright/TestPageLocatorQuery.java
@@ -16,6 +16,7 @@
package com.microsoft.playwright;
+import com.microsoft.playwright.options.AriaRole;
import org.junit.jupiter.api.Test;
import java.util.regex.Pattern;
@@ -207,4 +208,21 @@ public class TestPageLocatorQuery extends TestBase {
assertThat(page.locator("div").or(page.locator("article"))).hasText("hello");
assertThat(page.locator("span").or(page.locator("article"))).hasText("world");
}
+
+ @Test
+ void shouldSupportLocatorLocatorWithAndOr() {
+ page.setContent("\n" +
+ "
+ *
+ *
+ *
+ *
+ */
+ public String exposeNetwork;
/**
* Additional HTTP headers to be sent with web socket connect request. Optional.
*/
@@ -57,6 +77,29 @@ public interface BrowserType {
*/
public Double timeout;
+ /**
+ * This option exposes network available on the connecting client to the browser being connected to. Consists of a list of
+ * rules separated by comma.
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+ public ConnectOptions setExposeNetwork(String exposeNetwork) {
+ this.exposeNetwork = exposeNetwork;
+ return this;
+ }
/**
* Additional HTTP headers to be sent with web socket connect request. Optional.
*/
@@ -496,7 +539,7 @@ public interface BrowserType {
/**
* 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 mobile emulation.
+ * about mobile emulation.
*/
public Boolean isMobile;
/**
@@ -610,8 +653,8 @@ public interface BrowserType {
*/
public String userAgent;
/**
- * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
- * consistent viewport emulation. Learn more about viewport
+ * Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
+ * viewport emulation. Learn more about viewport
* emulation.
*
*