Skip to content

Commit d84a2db

Browse files
authored
chore: roll driver to 1.60.0-beta-1778180503000 (#1918)
1 parent f081667 commit d84a2db

8 files changed

Lines changed: 166 additions & 28 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom
1212
| :--- | :---: | :---: | :---: |
1313
| Chromium <!-- GEN:chromium-version -->148.0.7778.96<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
1414
| WebKit <!-- GEN:webkit-version -->26.4<!-- GEN:stop --> ||||
15-
| Firefox <!-- GEN:firefox-version -->150.0.1<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
15+
| Firefox <!-- GEN:firefox-version -->150.0.2<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
1616

1717
## Documentation
1818

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
public interface Screencast {
2828
class StartOptions {
2929
/**
30-
* Callback that receives JPEG-encoded frame data.
30+
* Callback that receives JPEG-encoded frame data along with the page viewport size at the time of capture.
3131
*/
3232
public Consumer<ScreencastFrame> onFrame;
3333
/**
@@ -40,7 +40,7 @@ class StartOptions {
4040
public Integer quality;
4141

4242
/**
43-
* Callback that receives JPEG-encoded frame data.
43+
* Callback that receives JPEG-encoded frame data along with the page viewport size at the time of capture.
4444
*/
4545
public StartOptions setOnFrame(Consumer<ScreencastFrame> onFrame) {
4646
this.onFrame = onFrame;

playwright/src/main/java/com/microsoft/playwright/options/ScreencastFrame.java renamed to playwright/src/main/java/com/microsoft/playwright/ScreencastFrame.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.microsoft.playwright.options;
17+
package com.microsoft.playwright;
1818

19-
/**
20-
* A single screencast frame delivered to {@link com.microsoft.playwright.Screencast#start Screencast.start()}'s
21-
* {@code onFrame} callback.
22-
*/
23-
public class ScreencastFrame {
19+
public interface ScreencastFrame {
2420
/**
2521
* JPEG-encoded frame data.
2622
*/
27-
public byte[] data;
23+
byte[] data();
24+
25+
/**
26+
* Width of the page viewport at the time the frame was captured.
27+
*/
28+
int viewportWidth();
2829

29-
public ScreencastFrame(byte[] data) {
30-
this.data = data;
31-
}
32-
}
30+
/**
31+
* Height of the page viewport at the time the frame was captured.
32+
*/
33+
int viewportHeight();
34+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.impl;
18+
19+
import com.microsoft.playwright.ScreencastFrame;
20+
21+
class ScreencastFrameImpl implements ScreencastFrame {
22+
private final byte[] data;
23+
private final int viewportWidth;
24+
private final int viewportHeight;
25+
26+
ScreencastFrameImpl(byte[] data, int viewportWidth, int viewportHeight) {
27+
this.data = data;
28+
this.viewportWidth = viewportWidth;
29+
this.viewportHeight = viewportHeight;
30+
}
31+
32+
@Override
33+
public byte[] data() {
34+
return data;
35+
}
36+
37+
@Override
38+
public int viewportWidth() {
39+
return viewportWidth;
40+
}
41+
42+
@Override
43+
public int viewportHeight() {
44+
return viewportHeight;
45+
}
46+
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.google.gson.JsonObject;
2020
import com.microsoft.playwright.PlaywrightException;
2121
import com.microsoft.playwright.Screencast;
22-
import com.microsoft.playwright.options.ScreencastFrame;
22+
import com.microsoft.playwright.ScreencastFrame;
2323

2424
import java.nio.file.Path;
2525
import java.util.function.Consumer;
@@ -44,7 +44,9 @@ void handleScreencastFrame(JsonObject params) {
4444
}
4545
String dataBase64 = params.get("data").getAsString();
4646
byte[] data = java.util.Base64.getDecoder().decode(dataBase64);
47-
onFrame.accept(new ScreencastFrame(data));
47+
int viewportWidth = params.get("viewportWidth").getAsInt();
48+
int viewportHeight = params.get("viewportHeight").getAsInt();
49+
onFrame.accept(new ScreencastFrameImpl(data, viewportWidth, viewportHeight));
4850
}
4951

5052
@Override

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.microsoft.playwright;
1818

19-
import com.microsoft.playwright.options.ScreencastFrame;
2019
import org.junit.jupiter.api.Test;
2120
import org.junit.jupiter.api.io.TempDir;
2221

@@ -113,9 +112,30 @@ void screencastStartShouldDeliverFramesViaOnFrame() throws Exception {
113112
assertFalse(frames.isEmpty(), "expected at least one frame");
114113
// JPEG-encoded frames start with FF D8.
115114
for (ScreencastFrame frame : frames) {
116-
assertNotNull(frame.data);
117-
assertEquals((byte) 0xFF, frame.data[0]);
118-
assertEquals((byte) 0xD8, frame.data[1]);
115+
assertNotNull(frame.data());
116+
assertEquals((byte) 0xFF, frame.data()[0]);
117+
assertEquals((byte) 0xD8, frame.data()[1]);
118+
}
119+
} finally {
120+
context.close();
121+
}
122+
}
123+
124+
@Test
125+
void onFrameShouldReceiveViewportSize() {
126+
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setViewportSize(1000, 400));
127+
Page page = context.newPage();
128+
try {
129+
List<ScreencastFrame> frames = new ArrayList<>();
130+
page.screencast().start(new Screencast.StartOptions().setOnFrame(frames::add));
131+
page.navigate(server.EMPTY_PAGE);
132+
page.evaluate("() => document.body.style.backgroundColor = 'red'");
133+
page.waitForTimeout(500);
134+
page.screencast().stop();
135+
assertFalse(frames.isEmpty(), "expected at least one frame");
136+
for (ScreencastFrame frame : frames) {
137+
assertEquals(1000, frame.viewportWidth());
138+
assertEquals(400, frame.viewportHeight());
119139
}
120140
} finally {
121141
context.close();

scripts/DRIVER_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.60.0-alpha-1778025033000
1+
1.60.0-beta-1778180503000

tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,22 @@ private void createClassesAndEnums(JsonObject jsonObject) {
326326
}
327327
return;
328328
}
329+
if ("function".equals(jsonObject.get("name").getAsString()) && jsonObject.has("args")) {
330+
for (JsonElement item : jsonObject.getAsJsonArray("args")) {
331+
if (!item.isJsonObject()) {
332+
continue;
333+
}
334+
JsonObject argObject = item.getAsJsonObject();
335+
if (!"Object".equals(argObject.get("name").getAsString())) {
336+
continue;
337+
}
338+
String alias = javaAlias(argObject);
339+
if (alias != null) {
340+
typeScope().createTopLevelInterface(alias, this, argObject);
341+
}
342+
}
343+
return;
344+
}
329345
if ("Object".equals(jsonObject.get("name").getAsString())) {
330346
if (customType != null) {
331347
// Same type maybe referenced as 'Object' in several union values, e.g. Object|Array<Object>
@@ -506,8 +522,8 @@ private String convertBuiltinType(JsonObject jsonType) {
506522
if (customType != null) {
507523
return customType;
508524
}
509-
// Inner Objects (e.g. function arguments) are not visited by createClassesAndEnums,
510-
// so resolve their Java type name from langAliases here.
525+
// Inner Objects without langAliases (e.g. unaliased function arguments) are not visited
526+
// by createClassesAndEnums, so resolve their Java type name from langAliases here.
511527
String alias = javaAlias(jsonType);
512528
if (alias != null) {
513529
return alias;
@@ -601,6 +617,14 @@ void createTopLevelClass(String name, Element parent, JsonObject jsonObject) {
601617
}
602618
}
603619

620+
void createTopLevelInterface(String name, Element parent, JsonObject jsonObject) {
621+
Map<String, TypeDefinition> map = topLevelTypes();
622+
TypeDefinition existing = map.putIfAbsent(name, new CustomInterface(parent, name, jsonObject));
623+
if (existing != null && !(existing instanceof CustomInterface)) {
624+
throw new RuntimeException("Two interfaces with same name have different values:\n" + jsonObject + "\n" + existing.jsonElement);
625+
}
626+
}
627+
604628
void createNestedClass(String name, Element parent, JsonObject jsonObject) {
605629
for (CustomClass c : classes) {
606630
if (c.name.equals(name)) {
@@ -840,7 +864,7 @@ class Field extends Element {
840864
final String name;
841865
final TypeRef type;
842866

843-
Field(CustomClass parent, String name, JsonObject jsonElement) {
867+
Field(TypeDefinition parent, String name, JsonObject jsonElement) {
844868
super(parent, jsonElement);
845869
this.name = name;
846870
this.type = new TypeRef(this, jsonElement.getAsJsonObject().get("type"));
@@ -1151,6 +1175,43 @@ private void writeConstructor(List<String> output, String bodyOffset) {
11511175
}
11521176
}
11531177

1178+
class CustomInterface extends TypeDefinition {
1179+
final String name;
1180+
final List<Field> fields = new ArrayList<>();
1181+
1182+
CustomInterface(Element parent, String name, JsonObject jsonElement) {
1183+
super(parent, true, jsonElement);
1184+
this.name = name;
1185+
if (jsonElement.has("properties")) {
1186+
for (JsonElement item : jsonElement.getAsJsonArray("properties")) {
1187+
JsonObject propertyJson = item.getAsJsonObject();
1188+
fields.add(new Field(this, propertyJson.get("name").getAsString(), propertyJson));
1189+
}
1190+
}
1191+
}
1192+
1193+
@Override
1194+
String name() {
1195+
return name;
1196+
}
1197+
1198+
@Override
1199+
void writeTo(List<String> output, String offset) {
1200+
output.add(offset + "public interface " + name + " {");
1201+
String bodyOffset = offset + " ";
1202+
boolean first = true;
1203+
for (Field f : fields) {
1204+
if (!first) {
1205+
output.add("");
1206+
}
1207+
first = false;
1208+
writeJavadoc(output, bodyOffset, f.comment());
1209+
output.add(bodyOffset + f.type.toJava() + " " + f.name + "();");
1210+
}
1211+
output.add(offset + "}");
1212+
}
1213+
}
1214+
11541215
class Enum extends TypeDefinition {
11551216
final List<String> enumValues;
11561217

@@ -1199,18 +1260,25 @@ public class ApiGenerator {
11991260
System.out.println("Writing assertion files to: " + dir.getCanonicalPath());
12001261
generate(api, assertionsDir, "com.microsoft.playwright.assertions", isAssertion().and(isSoftAssertion().negate()), sharedTypes);
12011262

1202-
writeTopLevelTypes(sharedTypes, optionsDir, "com.microsoft.playwright");
1263+
writeTopLevelTypes(sharedTypes, dir, optionsDir, "com.microsoft.playwright");
12031264
}
12041265

1205-
private void writeTopLevelTypes(Map<String, TypeDefinition> topLevelTypes, File optionsDir, String packageName) throws IOException {
1266+
private void writeTopLevelTypes(Map<String, TypeDefinition> topLevelTypes, File dir, File optionsDir, String packageName) throws IOException {
12061267
for (TypeDefinition e : topLevelTypes.values()) {
12071268
List<String> lines = new ArrayList<>();
12081269
lines.add(Interface.header);
1209-
lines.add("package " + packageName + ".options;");
1270+
File targetDir;
1271+
if (e instanceof CustomInterface) {
1272+
lines.add("package " + packageName + ";");
1273+
targetDir = dir;
1274+
} else {
1275+
lines.add("package " + packageName + ".options;");
1276+
targetDir = optionsDir;
1277+
}
12101278
lines.add("");
12111279
e.writeTo(lines, "");
12121280
String text = String.join("\n", lines);
1213-
try (FileWriter writer = new FileWriter(new File(optionsDir, e.name() + ".java"))) {
1281+
try (FileWriter writer = new FileWriter(new File(targetDir, e.name() + ".java"))) {
12141282
writer.write(text);
12151283
}
12161284
}

0 commit comments

Comments
 (0)