Skip to content

Commit 8cd136b

Browse files
authored
Merge branch 'trunk' into final-python-pagesize-support
2 parents 89b629b + 73f5ad4 commit 8cd136b

File tree

14 files changed

+190
-19
lines changed

14 files changed

+190
-19
lines changed

java/CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
v4.28.1
2+
======
3+
* [java]: Add Locale.ROOT to avoid port formatting issues for all drivers (#15121)
4+
* [java][bidi]: implement bidi setCacheBehavior (#15130)
5+
* [java] Enhance PageSize class to support for predefined and custom Paper Sizes (#15052)
6+
* [grid]: Grid UI could not open session live view (#15132)
7+
18
v4.28.0
29
======
310
* Add CDP for Chrome 132 and remove 129

java/src/org/openqa/selenium/bidi/module/Network.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.Collections;
2121
import java.util.HashSet;
22+
import java.util.List;
2223
import java.util.Map;
2324
import java.util.Set;
2425
import java.util.function.Consumer;
@@ -30,6 +31,7 @@
3031
import org.openqa.selenium.bidi.HasBiDi;
3132
import org.openqa.selenium.bidi.network.AddInterceptParameters;
3233
import org.openqa.selenium.bidi.network.BeforeRequestSent;
34+
import org.openqa.selenium.bidi.network.CacheBehavior;
3335
import org.openqa.selenium.bidi.network.ContinueRequestParameters;
3436
import org.openqa.selenium.bidi.network.ContinueResponseParameters;
3537
import org.openqa.selenium.bidi.network.FetchError;
@@ -137,6 +139,22 @@ public void provideResponse(ProvideResponseParameters parameters) {
137139
this.bidi.send(new Command<>("network.provideResponse", parameters.toMap()));
138140
}
139141

142+
public void setCacheBehavior(CacheBehavior cacheBehavior) {
143+
Require.nonNull("Cache behavior", cacheBehavior);
144+
this.bidi.send(
145+
new Command<>(
146+
"network.setCacheBehavior", Map.of("cacheBehavior", cacheBehavior.toString())));
147+
}
148+
149+
public void setCacheBehavior(CacheBehavior cacheBehavior, List<String> contexts) {
150+
Require.nonNull("Cache behavior", cacheBehavior);
151+
Require.nonNull("Contexts", contexts);
152+
this.bidi.send(
153+
new Command<>(
154+
"network.setCacheBehavior",
155+
Map.of("cacheBehavior", cacheBehavior.toString(), "contexts", contexts)));
156+
}
157+
140158
public void onBeforeRequestSent(Consumer<BeforeRequestSent> consumer) {
141159
if (browsingContextIds.isEmpty()) {
142160
this.bidi.addListener(beforeRequestSentEvent, consumer);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.network;
19+
20+
public enum CacheBehavior {
21+
DEFAULT("default"),
22+
BYPASS("bypass");
23+
24+
private final String behavior;
25+
26+
CacheBehavior(String behavior) {
27+
this.behavior = behavior;
28+
}
29+
30+
@Override
31+
public String toString() {
32+
return behavior;
33+
}
34+
}

java/src/org/openqa/selenium/print/PageSize.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@
2323

2424
@NullMarked
2525
public class PageSize {
26-
2726
private final double height;
2827
private final double width;
2928

29+
// Reference for predefined page size constants:
30+
// https://www.agooddaytoprint.com/page/paper-size-chart-faq
31+
public static final PageSize ISO_A4 = new PageSize(29.7, 21.0); // ISO_A4 size in cm
32+
public static final PageSize US_LEGAL = new PageSize(35.56, 21.59); // US_LEGAL size in cm
33+
public static final PageSize ANSI_TABLOID = new PageSize(43.18, 27.94); // ANSI_TABLOID size in cm
34+
public static final PageSize US_LETTER = new PageSize(27.94, 21.59); // US_LETTER size in cm
35+
3036
public PageSize() {
31-
// Initialize with defaults. A4 paper size defaults in cms.
32-
this.height = 27.94;
33-
this.width = 21.59;
37+
// Initialize with defaults. ISO_A4 paper size defaults in cms.
38+
this(ISO_A4.getHeight(), ISO_A4.getWidth());
3439
}
3540

3641
public PageSize(double height, double width) {
@@ -46,11 +51,23 @@ public double getWidth() {
4651
return width;
4752
}
4853

54+
public static PageSize setPageSize(PageSize pageSize) {
55+
if (pageSize == null) {
56+
throw new IllegalArgumentException("Page size cannot be null");
57+
}
58+
return new PageSize(pageSize.getHeight(), pageSize.getWidth());
59+
}
60+
4961
public Map<String, Object> toMap() {
5062
final Map<String, Object> options = new HashMap<>(7);
5163
options.put("height", getHeight());
5264
options.put("width", getWidth());
5365

5466
return options;
5567
}
68+
69+
@Override
70+
public String toString() {
71+
return "PageSize[width=" + this.getWidth() + ", height=" + this.getHeight() + "]";
72+
}
5673
}

java/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.time.Duration;
2525
import java.time.temporal.ChronoUnit;
26+
import java.util.Collections;
2627
import java.util.concurrent.CountDownLatch;
2728
import java.util.concurrent.TimeUnit;
2829
import org.junit.jupiter.api.Disabled;
@@ -32,6 +33,9 @@
3233
import org.openqa.selenium.TimeoutException;
3334
import org.openqa.selenium.UsernameAndPassword;
3435
import org.openqa.selenium.WebDriverException;
36+
import org.openqa.selenium.WindowType;
37+
import org.openqa.selenium.bidi.BiDiException;
38+
import org.openqa.selenium.bidi.browsingcontext.BrowsingContext;
3539
import org.openqa.selenium.bidi.module.Network;
3640
import org.openqa.selenium.support.ui.ExpectedConditions;
3741
import org.openqa.selenium.testing.JupiterTestBase;
@@ -264,4 +268,56 @@ void canFailRequest() {
264268
assertThatThrownBy(() -> driver.get(page)).isInstanceOf(WebDriverException.class);
265269
}
266270
}
271+
272+
@Test
273+
@NeedsFreshDriver
274+
void canSetCacheBehaviorToBypass() {
275+
try (Network network = new Network(driver)) {
276+
page = appServer.whereIs("basicAuth");
277+
278+
BrowsingContext context = new BrowsingContext(driver, WindowType.TAB);
279+
String contextId = context.getId();
280+
281+
network.setCacheBehavior(CacheBehavior.BYPASS, Collections.singletonList(contextId));
282+
}
283+
}
284+
285+
@Test
286+
@NeedsFreshDriver
287+
void canSetCacheBehaviorToDefault() {
288+
try (Network network = new Network(driver)) {
289+
page = appServer.whereIs("basicAuth");
290+
291+
BrowsingContext context = new BrowsingContext(driver, WindowType.TAB);
292+
String contextId = context.getId();
293+
294+
network.setCacheBehavior(CacheBehavior.DEFAULT, Collections.singletonList(contextId));
295+
}
296+
}
297+
298+
@Test
299+
@NeedsFreshDriver
300+
void canSetCacheBehaviorWithNoContextId() {
301+
try (Network network = new Network(driver)) {
302+
page = appServer.whereIs("basicAuth");
303+
304+
network.setCacheBehavior(CacheBehavior.BYPASS);
305+
network.setCacheBehavior(CacheBehavior.DEFAULT);
306+
}
307+
}
308+
309+
@Test
310+
@NeedsFreshDriver
311+
void throwsExceptionForInvalidContext() {
312+
try (Network network = new Network(driver)) {
313+
page = appServer.whereIs("basicAuth");
314+
315+
assertThatThrownBy(
316+
() ->
317+
network.setCacheBehavior(
318+
CacheBehavior.DEFAULT, Collections.singletonList("invalid-context")))
319+
.isInstanceOf(BiDiException.class)
320+
.hasMessageContaining("no such frame");
321+
}
322+
}
267323
}

java/test/org/openqa/selenium/print/PageSizeTest.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,53 @@
1919

2020
import static org.assertj.core.api.Assertions.assertThat;
2121

22+
import org.junit.jupiter.api.BeforeEach;
2223
import org.junit.jupiter.api.Tag;
2324
import org.junit.jupiter.api.Test;
2425

2526
@Tag("UnitTests")
2627
class PageSizeTest {
2728

28-
// Defaults assertion
29-
private static final double HEIGHT = 27.94;
30-
private static final double WIDTH = 21.59;
29+
private PrintOptions printOptions;
30+
31+
@BeforeEach
32+
void setUp() {
33+
printOptions = new PrintOptions();
34+
}
3135

3236
@Test
3337
void setsDefaultHeightWidth() {
3438
PageSize pageSize = new PageSize();
39+
assertThat(pageSize.getHeight()).isEqualTo(29.7);
40+
assertThat(pageSize.getWidth()).isEqualTo(21.0);
41+
}
42+
43+
@Test
44+
void verifiesPageSizeA4() {
45+
46+
printOptions.setPageSize(PageSize.ISO_A4);
47+
assertThat(printOptions.getPageSize().getHeight()).isEqualTo(29.7);
48+
assertThat(printOptions.getPageSize().getWidth()).isEqualTo(21.0);
49+
}
3550

36-
assertThat(pageSize.getHeight()).isEqualTo(HEIGHT);
37-
assertThat(pageSize.getWidth()).isEqualTo(WIDTH);
51+
@Test
52+
void verifiesPageSizeLegal() {
53+
printOptions.setPageSize(PageSize.US_LEGAL);
54+
assertThat(printOptions.getPageSize().getHeight()).isEqualTo(35.56);
55+
assertThat(printOptions.getPageSize().getWidth()).isEqualTo(21.59);
56+
}
57+
58+
@Test
59+
void verifiesPageSizeLetter() {
60+
printOptions.setPageSize(PageSize.US_LETTER);
61+
assertThat(printOptions.getPageSize().getHeight()).isEqualTo(27.94);
62+
assertThat(printOptions.getPageSize().getWidth()).isEqualTo(21.59);
63+
}
64+
65+
@Test
66+
void verifiesPageSizeTabloid() {
67+
printOptions.setPageSize(PageSize.ANSI_TABLOID);
68+
assertThat(printOptions.getPageSize().getHeight()).isEqualTo(43.18);
69+
assertThat(printOptions.getPageSize().getWidth()).isEqualTo(27.94);
3870
}
3971
}

java/version.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
SE_VERSION = "4.29.0-SNAPSHOT"
1+
SE_VERSION = "4.28.1"
22
TOOLS_JAVA_VERSION = "17"

javascript/grid-ui/src/components/LiveView/LiveView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ const LiveView = forwardRef((props, ref) => {
6060
return
6161
}
6262

63-
const newRfb = new RFB(canvas, props.url, {})
63+
const newRfb = new RFB.default(canvas, props.url, {})
6464
newRfb.scaleViewport = props.scaleViewport
6565
newRfb.background = 'rgb(247,248,248)'
6666
newRfb.addEventListener('credentialsrequired', handleCredentials)
6767
newRfb.addEventListener('securityfailure', securityFailed)
6868
newRfb.addEventListener('connect', connectedToServer)
69+
newRfb.addEventListener('disconnect', disconnect)
6970
setRfb(newRfb)
7071
}
7172

py/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ compile_pip_requirements(
6262
],
6363
)
6464

65-
SE_VERSION = "4.29.0.202501201850"
65+
SE_VERSION = "4.28.1"
6666

6767
BROWSER_VERSIONS = [
6868
"v85",

py/CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Selenium 4.28.1
2+
* [py] Fix installing most of the data from source distributions
3+
14
Selenium 4.28.0
25
* Add CDP for Chrome 132 and remove 129
36
* [py] fix packaging (#14823)

0 commit comments

Comments
 (0)