Skip to content

Commit 14c66f9

Browse files
committed
1.54.0-alpha-2025-07-08
1 parent dbd6070 commit 14c66f9

File tree

12 files changed

+119
-26
lines changed

12 files changed

+119
-26
lines changed

playwright/src/main/java/com/microsoft/playwright/ConsoleMessage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.microsoft.playwright;
1818

19+
import com.microsoft.playwright.options.*;
1920
import java.util.*;
2021

2122
/**
@@ -77,6 +78,6 @@ public interface ConsoleMessage {
7778
*
7879
* @since v1.8
7980
*/
80-
String type();
81+
ConsoleMessageType type();
8182
}
8283

playwright/src/main/java/com/microsoft/playwright/impl/BrowserContextImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ private void routeWebSocketImpl(UrlMatcher matcher, Consumer<WebSocketRoute> han
506506

507507
void recordIntoHar(PageImpl page, Path har, RouteFromHAROptions options, HarContentPolicy contentPolicy) {
508508
if (contentPolicy == null) {
509-
contentPolicy = Utils.convertType(options.updateContent, HarContentPolicy.class);;
509+
contentPolicy = Utils.convertType(options.updateContent, HarContentPolicy.class);
510510
}
511511
if (contentPolicy == null) {
512512
contentPolicy = HarContentPolicy.ATTACH;

playwright/src/main/java/com/microsoft/playwright/impl/ConsoleMessageImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.microsoft.playwright.ConsoleMessage;
2222
import com.microsoft.playwright.JSHandle;
2323
import com.microsoft.playwright.Page;
24+
import com.microsoft.playwright.options.ConsoleMessageType;
2425

2526
import java.util.ArrayList;
2627
import java.util.List;
@@ -43,8 +44,8 @@ public ConsoleMessageImpl(Connection connection, JsonObject initializer) {
4344
this.initializer = initializer;
4445
}
4546

46-
public String type() {
47-
return initializer.get("type").getAsString();
47+
public ConsoleMessageType type() {
48+
return Utils.convertType(initializer.get("type").getAsString(), ConsoleMessageType.class);
4849
}
4950

5051
public String text() {

playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,8 @@ ElementHandle waitForSelectorImpl(String selector, WaitForSelectorOptions option
993993
@Override
994994
public void waitForTimeout(double timeout) {
995995
JsonObject params = new JsonObject();
996-
sendMessage("waitForTimeout", params, timeout);
996+
params.addProperty("waitTimeout", timeout);
997+
sendMessage("waitForTimeout", params, NO_TIMEOUT);
997998
}
998999

9991000
@Override

playwright/src/main/java/com/microsoft/playwright/impl/SelectorsImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public void register(String name, Path path, RegisterOptions options) {
6868
}
6969

7070
private void registerImpl(String name, String script, RegisterOptions options) {
71+
if (selectorEngines.stream().anyMatch(engine -> name.equals(engine.get("name").getAsString()))) {
72+
throw new PlaywrightException("selectors.register: \"" + name + "\" selector engine has been already registered");
73+
}
74+
7175
JsonObject engine = new JsonObject();
7276
engine.addProperty("name", name);
7377
engine.addProperty("source", script);

playwright/src/main/java/com/microsoft/playwright/impl/WebSocketRouteImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ void afterHandle() {
128128
return;
129129
}
130130
// Ensure that websocket is "open" and can send messages without an actual server connection.
131-
sendMessageAsync("ensureOpened");
131+
try {
132+
sendMessageAsync("ensureOpened");
133+
} catch (PlaywrightException e) {
134+
// If this happens after the page has been closed, ignore the error.
135+
}
132136
}
133137

134138
@Override
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.microsoft.playwright.options;
18+
19+
public enum ConsoleMessageType {
20+
LOG,
21+
DEBUG,
22+
INFO,
23+
ERROR,
24+
WARNING,
25+
DIR,
26+
DIRXML,
27+
TABLE,
28+
TRACE,
29+
CLEAR,
30+
STARTGROUP,
31+
STARTGROUPCOLLAPSED,
32+
ENDGROUP,
33+
ASSERT,
34+
PROFILE,
35+
PROFILEEND,
36+
COUNT,
37+
TIMEEND
38+
}

playwright/src/test/java/com/microsoft/playwright/TestPageAriaSnapshot.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.microsoft.playwright.junit.FixtureTest;
44
import com.microsoft.playwright.junit.UsePlaywright;
55
import org.junit.jupiter.api.Test;
6+
import org.opentest4j.AssertionFailedError;
67

78
import java.util.Arrays;
89
import java.util.List;
@@ -12,6 +13,7 @@
1213

1314
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
1415
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertThrows;
1517

1618
@FixtureTest
1719
@UsePlaywright
@@ -102,4 +104,27 @@ void shouldMatchUrl(Page page) {
102104
"- link:\n" +
103105
" - /url: /.*example.com/");
104106
}
107+
108+
@Test
109+
void shouldHandleTopLevelDeepEqual(Page page) {
110+
// https://github.com/microsoft/playwright/issues/36456
111+
page.setContent("" +
112+
"<ul>\n" +
113+
" <li>\n" +
114+
" <ul>\n" +
115+
" <li>1.1</li>\n" +
116+
" <li>1.2</li>\n" +
117+
" </ul>\n" +
118+
" </li>\n" +
119+
"</ul>");
120+
121+
assertThrows(AssertionFailedError.class, () -> {
122+
assertThat(page.locator("body")).matchesAriaSnapshot("" +
123+
"- /children: deep-equal\n" +
124+
"- list:\n" +
125+
" - listitem:\n" +
126+
" - listitem: \"1.1\"\n" +
127+
" - listitem: \"1.2\"");
128+
});
129+
}
105130
}

playwright/src/test/java/com/microsoft/playwright/TestPageInterception.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,14 @@ void shouldWorkWithGlob() {
199199
assertTrue(urlMatches("http://first.host/", "http://second.host/foo", "**/foo"));
200200
assertTrue(urlMatches("http://playwright.dev/", "http://localhost/", "*//localhost/"));
201201

202-
assertTrue(urlMatches("http://playwright.dev/", "about:blank", "about:blank"));
203-
assertFalse(urlMatches("http://playwright.dev/", "about:blank", "http://playwright.dev/"));
204-
assertTrue(urlMatches(null, "about:blank", "about:blank"));
205-
assertTrue(urlMatches(null, "about:blank", "about:*"));
206-
assertFalse(urlMatches(null, "notabout:blank", "about:*"));
202+
String[] customPrefixes = {"about", "data", "chrome", "edge", "file"};
203+
for (String prefix : customPrefixes) {
204+
assertTrue(urlMatches("http://playwright.dev/", prefix + ":blank", prefix + ":blank"));
205+
assertFalse(urlMatches("http://playwright.dev/", prefix + ":blank", "http://playwright.dev/"));
206+
assertTrue(urlMatches(null, prefix + ":blank", prefix + ":blank"));
207+
assertTrue(urlMatches(null, prefix + ":blank", prefix + ":*"));
208+
assertFalse(urlMatches(null, "not" + prefix + ":blank", prefix + ":*"));
209+
}
207210
}
208211

209212
Pattern globToRegex(String glob) {

playwright/src/test/java/com/microsoft/playwright/TestSelectorsRegister.java

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,26 @@
2323
import static org.junit.jupiter.api.Assertions.*;
2424

2525
public class TestSelectorsRegister extends TestBase {
26+
private static final String TAG_SELECTOR_SCRIPT = "{\n" +
27+
" create(root, target) {\n" +
28+
" return target.nodeName;\n" +
29+
" },\n" +
30+
" query(root, selector) {\n" +
31+
" return root.querySelector(selector);\n" +
32+
" },\n" +
33+
" queryAll(root, selector) {\n" +
34+
" return Array.from(root.querySelectorAll(selector));\n" +
35+
" }\n" +
36+
"}";
37+
2638
@Test
2739
void shouldWork() {
28-
String selectorScript = "{\n" +
29-
" create(root, target) {\n" +
30-
" return target.nodeName;\n" +
31-
" },\n" +
32-
" query(root, selector) {\n" +
33-
" return root.querySelector(selector);\n" +
34-
" },\n" +
35-
" queryAll(root, selector) {\n" +
36-
" return Array.from(root.querySelectorAll(selector));\n" +
37-
" }\n" +
38-
"}";
3940
// Register one engine before creating context.
40-
playwright.selectors().register("tag", selectorScript);
41+
playwright.selectors().register("tag", TAG_SELECTOR_SCRIPT);
4142

4243
BrowserContext context = browser.newContext();
4344
// Register another engine after creating context.
44-
playwright.selectors().register("tag2", selectorScript);
45+
playwright.selectors().register("tag2", TAG_SELECTOR_SCRIPT);
4546

4647
Page page = context.newPage();
4748
page.setContent("<div><span></span></div><div></div>");
@@ -134,4 +135,19 @@ void shouldHandleErrors() {
134135
});
135136
assertTrue(e.getMessage().contains("\"css\" is a predefined selector engine"));
136137
}
138+
139+
@Test
140+
void shouldThrowAlreadyRegisteredErrorWhenRegistering() {
141+
// https://github.com/microsoft/playwright/issues/36467
142+
browser.close();
143+
144+
// Register the selector engine first
145+
playwright.selectors().register("alreadyRegistered", TAG_SELECTOR_SCRIPT);
146+
147+
// Attempt to register the same selector engine again should throw an error
148+
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
149+
playwright.selectors().register("alreadyRegistered", TAG_SELECTOR_SCRIPT);
150+
});
151+
assertTrue(e.getMessage().contains("\"alreadyRegistered\" selector engine has been already registered"));
152+
}
137153
}

0 commit comments

Comments
 (0)