Skip to content

Commit

Permalink
Merge branch 'trunk' into print-page-size-options
Browse files Browse the repository at this point in the history
  • Loading branch information
yvsvarma authored Jan 17, 2025
2 parents 0eae862 + 487b9a2 commit 0ee9e1b
Show file tree
Hide file tree
Showing 21 changed files with 428 additions and 209 deletions.
6 changes: 3 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ maven.install(
"org.zeromq:jeromq:0.6.0",
],
boms = [
"io.opentelemetry:opentelemetry-bom:1.44.1",
"io.netty:netty-bom:4.1.115.Final",
"org.junit:junit-bom:5.11.3",
"io.opentelemetry:opentelemetry-bom:1.46.0",
"io.netty:netty-bom:4.1.117.Final",
"org.junit:junit-bom:5.11.4",
],
excluded_artifacts = [
"org.hamcrest:hamcrest-all", # Replaced by hamcrest 2
Expand Down
190 changes: 95 additions & 95 deletions java/maven_install.json

Large diffs are not rendered by default.

45 changes: 24 additions & 21 deletions java/src/org/openqa/selenium/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
* Configuration parameters for using proxies in WebDriver. Generally you should pass an object of
Expand All @@ -34,6 +36,7 @@
* configuration. That is, it is an error to set an <code>httpProxy</code> manually and then turn on
* proxy autodetect.
*/
@NullMarked
public class Proxy {

public enum ProxyType {
Expand Down Expand Up @@ -77,15 +80,15 @@ public String toString() {

private ProxyType proxyType = ProxyType.UNSPECIFIED;
private boolean autodetect = false;
private String ftpProxy;
private String httpProxy;
private String noProxy;
private String sslProxy;
private String socksProxy;
private Integer socksVersion;
private String socksUsername;
private String socksPassword;
private String proxyAutoconfigUrl;
private @Nullable String ftpProxy;
private @Nullable String httpProxy;
private @Nullable String noProxy;
private @Nullable String sslProxy;
private @Nullable String socksProxy;
private @Nullable Integer socksVersion;
private @Nullable String socksUsername;
private @Nullable String socksPassword;
private @Nullable String proxyAutoconfigUrl;

public Proxy() {
// Empty default constructor
Expand Down Expand Up @@ -120,7 +123,7 @@ public Proxy(Map<String, ?> raw) {
setters.put(AUTODETECT, value -> setAutodetect((Boolean) value));
raw.forEach(
(key, value) -> {
if (key != null && value != null) {
if (key != null && value != null && setters.containsKey(key)) {
setters.get(key).accept(value);
}
});
Expand Down Expand Up @@ -223,7 +226,7 @@ public Proxy setAutodetect(boolean autodetect) {
*
* @return the FTP proxy hostname if present, or null if not set
*/
public String getFtpProxy() {
public @Nullable String getFtpProxy() {
return ftpProxy;
}

Expand All @@ -245,7 +248,7 @@ public Proxy setFtpProxy(String ftpProxy) {
*
* @return the HTTP proxy hostname if present, or null if not set
*/
public String getHttpProxy() {
public @Nullable String getHttpProxy() {
return httpProxy;
}

Expand All @@ -267,7 +270,7 @@ public Proxy setHttpProxy(String httpProxy) {
*
* @return The proxy bypass (noproxy) addresses
*/
public String getNoProxy() {
public @Nullable String getNoProxy() {
return noProxy;
}

Expand All @@ -289,7 +292,7 @@ public Proxy setNoProxy(String noProxy) {
*
* @return the SSL tunnel proxy hostname if present, null otherwise
*/
public String getSslProxy() {
public @Nullable String getSslProxy() {
return sslProxy;
}

Expand All @@ -311,7 +314,7 @@ public Proxy setSslProxy(String sslProxy) {
*
* @return the SOCKS proxy if present, null otherwise
*/
public String getSocksProxy() {
public @Nullable String getSocksProxy() {
return socksProxy;
}

Expand All @@ -333,7 +336,7 @@ public Proxy setSocksProxy(String socksProxy) {
*
* @return the SOCKS version if present, null otherwise
*/
public Integer getSocksVersion() {
public @Nullable Integer getSocksVersion() {
return socksVersion;
}

Expand All @@ -355,7 +358,7 @@ public Proxy setSocksVersion(Integer socksVersion) {
*
* @return the SOCKS proxy's username
*/
public String getSocksUsername() {
public @Nullable String getSocksUsername() {
return socksUsername;
}

Expand All @@ -377,7 +380,7 @@ public Proxy setSocksUsername(String username) {
*
* @return the SOCKS proxy's password
*/
public String getSocksPassword() {
public @Nullable String getSocksPassword() {
return socksPassword;
}

Expand All @@ -399,7 +402,7 @@ public Proxy setSocksPassword(String password) {
*
* @return the proxy auto-configuration URL
*/
public String getProxyAutoconfigUrl() {
public @Nullable String getProxyAutoconfigUrl() {
return proxyAutoconfigUrl;
}

Expand Down Expand Up @@ -428,7 +431,7 @@ private void verifyProxyTypeCompatibility(ProxyType compatibleProxy) {
}

@SuppressWarnings({"unchecked"})
public static Proxy extractFrom(Capabilities capabilities) {
public static @Nullable Proxy extractFrom(Capabilities capabilities) {
Object rawProxy = capabilities.getCapability("proxy");
Proxy proxy = null;
if (rawProxy != null) {
Expand Down Expand Up @@ -472,7 +475,7 @@ public String toString() {
}

@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions java/src/org/openqa/selenium/print/PageMargin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import java.util.HashMap;
import java.util.Map;
import org.jspecify.annotations.NullMarked;

@NullMarked
public class PageMargin {
private final double top;
private final double bottom;
Expand Down
2 changes: 2 additions & 0 deletions java/src/org/openqa/selenium/print/PageSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import java.util.HashMap;
import java.util.Map;
import org.jspecify.annotations.NullMarked;

@NullMarked
public class PageSize {
private final double height;
private final double width;
Expand Down
7 changes: 5 additions & 2 deletions java/src/org/openqa/selenium/print/PrintOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.internal.Require;

@NullMarked
public class PrintOptions {

public enum Orientation {
Expand All @@ -46,7 +49,7 @@ public String toString() {
private boolean shrinkToFit = true;
private PageSize pageSize = new PageSize();
private PageMargin pageMargin = new PageMargin();
private String[] pageRanges;
private String @Nullable [] pageRanges;

public Orientation getOrientation() {
return this.orientation;
Expand All @@ -56,7 +59,7 @@ public void setOrientation(Orientation orientation) {
this.orientation = Require.nonNull("orientation", orientation);
}

public String[] getPageRanges() {
public String @Nullable [] getPageRanges() {
return this.pageRanges;
}

Expand Down
12 changes: 12 additions & 0 deletions java/src/org/openqa/selenium/remote/service/DriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.net.URL;
import java.time.Duration;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -504,6 +505,17 @@ public DS build() {
port = PortProber.findFreePort();
}

if (Locale.getDefault(Locale.Category.FORMAT).getLanguage().equals("ar")) {
throw new NumberFormatException(
String.format(
"Couldn't format the port numbers because the System Language is arabic:"
+ " \"--port=%d\", please make sure to add the required arguments"
+ " \"-Duser.language=en -Duser.region=US\" to your JVM, for more info please"
+ " visit :%n"
+ " https://www.selenium.dev/documentation/webdriver/browsers/",
getPort()));
}

if (timeout == null) {
timeout = getDefaultTimeout();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,23 @@ void canExecuteCdpCommands() {

@Test
@NoDriverBeforeTest
void shouldLaunchSuccessfullyWithArabicDate() {
void shouldThrowNumberFormatException() {
Locale arabicLocale = new Locale("ar", "EG");
Locale.setDefault(arabicLocale);
Locale.setDefault(Locale.US);

int port = PortProber.findFreePort();
ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
builder.usingPort(port);
ChromeDriverService service = builder.build();

driver = new ChromeDriver(service, (ChromeOptions) CHROME.getCapabilities());
driver.get(pages.simpleTestPage);
assertThat(driver.getTitle()).isEqualTo("Hello WebDriver");
assertThatExceptionOfType(NumberFormatException.class)
.isThrownBy(builder::build)
.withMessage(
"Couldn't format the port numbers because the System Language is arabic: \""
+ String.format("--port=%d", port)
+ "\", please make sure to add the required arguments \"-Duser.language=en"
+ " -Duser.region=US\" to your JVM, for more info please visit :\n"
+ " https://www.selenium.dev/documentation/webdriver/browsers/");

Locale.setDefault(Locale.US);
}
}
16 changes: 10 additions & 6 deletions java/test/org/openqa/selenium/edge/EdgeDriverFunctionalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,23 @@ void canExecuteCdpCommands() {

@Test
@NoDriverBeforeTest
void shouldLaunchSuccessfullyWithArabicDate() {
void shouldThrowNumberFormatException() {
Locale arabicLocale = new Locale("ar", "EG");
Locale.setDefault(arabicLocale);
Locale.setDefault(Locale.US);

int port = PortProber.findFreePort();
EdgeDriverService.Builder builder = new EdgeDriverService.Builder();
builder.usingPort(port);
EdgeDriverService service = builder.build();

driver = new EdgeDriver(service, (EdgeOptions) EDGE.getCapabilities());
assertThatExceptionOfType(NumberFormatException.class)
.isThrownBy(builder::build)
.withMessage(
"Couldn't format the port numbers because the System Language is arabic: \""
+ String.format("--port=%d", port)
+ "\", please make sure to add the required arguments \"-Duser.language=en"
+ " -Duser.region=US\" to your JVM, for more info please visit :\n"
+ " https://www.selenium.dev/documentation/webdriver/browsers/");

driver.get(pages.simpleTestPage);
assertThat(driver.getTitle()).isEqualTo("Hello WebDriver");
Locale.setDefault(Locale.US);
}
}
18 changes: 12 additions & 6 deletions java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.selenium.firefox;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
Expand Down Expand Up @@ -272,19 +273,24 @@ void canSetContext() {

@Test
@NoDriverBeforeTest
void shouldLaunchSuccessfullyWithArabicDate() {
void shouldThrowNumberFormatException() {
Locale arabicLocale = new Locale("ar", "EG");
Locale.setDefault(arabicLocale);
Locale.setDefault(Locale.US);

int port = PortProber.findFreePort();
GeckoDriverService.Builder builder = new GeckoDriverService.Builder();
builder.usingPort(port);
GeckoDriverService service = builder.build();

driver = new FirefoxDriver(service, (FirefoxOptions) FIREFOX.getCapabilities());
driver.get(pages.simpleTestPage);
assertThat(driver.getTitle()).isEqualTo("Hello WebDriver");
assertThatExceptionOfType(NumberFormatException.class)
.isThrownBy(builder::build)
.withMessage(
"Couldn't format the port numbers because the System Language is arabic: \""
+ String.format("--port=%d", port)
+ "\", please make sure to add the required arguments \"-Duser.language=en"
+ " -Duser.region=US\" to your JVM, for more info please visit :\n"
+ " https://www.selenium.dev/documentation/webdriver/browsers/");

Locale.setDefault(Locale.US);
}

private static class CustomFirefoxProfile extends FirefoxProfile {}
Expand Down
24 changes: 24 additions & 0 deletions java/test/org/openqa/selenium/ie/InternetExplorerDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.awt.*;
import java.time.Duration;
import java.util.Locale;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
Expand All @@ -33,6 +34,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.testing.JupiterTestBase;
Expand Down Expand Up @@ -143,6 +145,28 @@ void testPersistentHoverCanBeTurnedOff() throws Exception {
assertThat(item.getText()).isEmpty();
}

@Test
@NoDriverBeforeTest
void shouldThrowNumberFormatException() {
Locale arabicLocale = new Locale("ar", "EG");
Locale.setDefault(arabicLocale);

int port = PortProber.findFreePort();
InternetExplorerDriverService.Builder builder = new InternetExplorerDriverService.Builder();
builder.usingPort(port);

assertThatExceptionOfType(NumberFormatException.class)
.isThrownBy(builder::build)
.withMessage(
"Couldn't format the port numbers because the System Language is arabic: \""
+ String.format("--port=%d", port)
+ "\", please make sure to add the required arguments \"-Duser.language=en"
+ " -Duser.region=US\" to your JVM, for more info please visit :\n"
+ " https://www.selenium.dev/documentation/webdriver/browsers/");

Locale.setDefault(Locale.US);
}

private WebDriver newIeDriver() {
return new WebDriverBuilder().get();
}
Expand Down
Loading

0 comments on commit 0ee9e1b

Please sign in to comment.