diff --git a/java/src/org/openqa/selenium/remote/service/DriverService.java b/java/src/org/openqa/selenium/remote/service/DriverService.java index 87d7e7cb75d61..9e70372d300bd 100644 --- a/java/src/org/openqa/selenium/remote/service/DriverService.java +++ b/java/src/org/openqa/selenium/remote/service/DriverService.java @@ -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; @@ -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(); } diff --git a/java/test/org/openqa/selenium/chrome/ChromeDriverFunctionalTest.java b/java/test/org/openqa/selenium/chrome/ChromeDriverFunctionalTest.java index ebf7000be83cb..6be2366ebf372 100644 --- a/java/test/org/openqa/selenium/chrome/ChromeDriverFunctionalTest.java +++ b/java/test/org/openqa/selenium/chrome/ChromeDriverFunctionalTest.java @@ -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); } } diff --git a/java/test/org/openqa/selenium/edge/EdgeDriverFunctionalTest.java b/java/test/org/openqa/selenium/edge/EdgeDriverFunctionalTest.java index c8feca9c42834..a2fa5a38d0539 100644 --- a/java/test/org/openqa/selenium/edge/EdgeDriverFunctionalTest.java +++ b/java/test/org/openqa/selenium/edge/EdgeDriverFunctionalTest.java @@ -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); } } diff --git a/java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java b/java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java index 8714a26938cf4..85e0a7fe1c398 100644 --- a/java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java +++ b/java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java @@ -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; @@ -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 {} diff --git a/java/test/org/openqa/selenium/ie/InternetExplorerDriverTest.java b/java/test/org/openqa/selenium/ie/InternetExplorerDriverTest.java index 26c9637121ba0..c93e1361195cf 100644 --- a/java/test/org/openqa/selenium/ie/InternetExplorerDriverTest.java +++ b/java/test/org/openqa/selenium/ie/InternetExplorerDriverTest.java @@ -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; @@ -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; @@ -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(); } diff --git a/java/test/org/openqa/selenium/safari/SafariDriverTest.java b/java/test/org/openqa/selenium/safari/SafariDriverTest.java index 1fc92e1b730b8..6312c0ad1e211 100644 --- a/java/test/org/openqa/selenium/safari/SafariDriverTest.java +++ b/java/test/org/openqa/selenium/safari/SafariDriverTest.java @@ -27,6 +27,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; +import java.util.Locale; import org.junit.jupiter.api.Test; import org.openqa.selenium.Capabilities; import org.openqa.selenium.SessionNotCreatedException; @@ -133,4 +134,26 @@ public void canAttachDebugger() { localDriver = new WebDriverBuilder().get(new SafariOptions()); ((HasDebugger) localDriver).attachDebugger(); } + + @Test + @NoDriverBeforeTest + void shouldThrowNumberFormatException() { + Locale arabicLocale = new Locale("ar", "EG"); + Locale.setDefault(arabicLocale); + + int port = PortProber.findFreePort(); + SafariDriverService.Builder builder = new SafariDriverService.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); + } }