Skip to content

Commit e28ba1f

Browse files
[Java] Migrate the String.Format to String.Format(Locale.US) to handle different langauges for Edge, Chrome and Firefox (#13934)
* *Changes Done: - Migrate the String.Format to Formatter.Format in : - ChromeDriverSerivce.java - EdgeDriverService.java - RemoteWebDriver.java *Issue Explaination: - Having System Date & Language in Arabic caused with driver setup. Using String.Format for ports and some other lines caused them to be localized in the system language and in arabic case it caused the numbers and some other character to be localized in arabic, e.g. the port. And that caused an issues when appending the port to the URL in order to setup the browser *Fix explaination: - Now it's utilizaing the Formatter.Format and forcing the localization to be in English.US in the Formatter Constructor * - Apply Suggested Code Enhancements from "codiumai-pr-agent-pro" to the classes changed: - ChromeDriverSerivce.java - EdgeDriverService.java - RemoteWebDriver.java *Changes Done: - Add try with resoruces to handle memory leaks where it's applicables - Changing String.ValueOf to ToString() * * Refactor The Formatting Logic for better optimzation in classes: - ChromeDriverService.java - EdgeDriverService.java - RemoteWebDriver.java - DriverService.java * Add Tests for both Edge and Chrome: - ChromeArabicDateTest.java at test/chrome - EdgeArabicDateTest.java at test/edge * - Added Logic for formatting the required configurations in GekoDriverService.java - Added Test Class for FirefoxArabicDateTest.java -Refactored the code of EdgeArabicDateTest.java And ChromeArabicDateTest.java to follow the same approach * Refactor the Formatter to String.format with Localization in - ChromeDriverService.java - EdgeDriverService.java - GeckoDriverService.java - RemoteWebDriver.java - DriverService.java * Fix spacing * Refactor FirefoxArabicDateTest : - Test added to LARGE_TESTS in BUILD.bazel - Refacotor the Test Logic * Fix spacing in FirefoxArabicDateTest.java * Tests Refactoring : - EdgeArabicDateTest.java - ChomeArabicDateTest.java - FirefoxArabicDateTest.java * [java] Fix formatting * Revert The Changes done to: - DriverService.java - RemoteWebDriver.java Change the logic to Locale.setDefault in : - ChomeDriverSerivce.java - EdgeDriverService.java - GeckDriverService.java * Fix Spaces * Fix Formatting * - Delete the Added Arabic Test Classes - Methods are added to the Functional Test Class for each driver accordingly * - Reverse changes made to class files * Fixing the Tests --------- Co-authored-by: Puja Jagani <[email protected]>
1 parent 0b2bb9a commit e28ba1f

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

java/test/org/openqa/selenium/chrome/ChromeDriverFunctionalTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.common.util.concurrent.Uninterruptibles;
2828
import java.time.Duration;
2929
import java.util.List;
30+
import java.util.Locale;
3031
import java.util.Map;
3132
import org.assertj.core.api.Assumptions;
3233
import org.junit.jupiter.api.Test;
@@ -40,6 +41,7 @@
4041
import org.openqa.selenium.chromium.HasCdp;
4142
import org.openqa.selenium.chromium.HasNetworkConditions;
4243
import org.openqa.selenium.chromium.HasPermissions;
44+
import org.openqa.selenium.net.PortProber;
4345
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
4446
import org.openqa.selenium.remote.http.ClientConfig;
4547
import org.openqa.selenium.testing.Ignore;
@@ -200,4 +202,21 @@ void canExecuteCdpCommands() {
200202

201203
assertThat(driver.getTitle()).isEqualTo("Hello WebDriver");
202204
}
205+
206+
@Test
207+
@NoDriverBeforeTest
208+
void shouldLaunchSuccessfullyWithArabicDate() {
209+
Locale arabicLocale = new Locale("ar", "EG");
210+
Locale.setDefault(arabicLocale);
211+
Locale.setDefault(Locale.US);
212+
213+
int port = PortProber.findFreePort();
214+
ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
215+
builder.usingPort(port);
216+
ChromeDriverService service = builder.build();
217+
218+
driver = new ChromeDriver(service, (ChromeOptions) CHROME.getCapabilities());
219+
driver.get(pages.simpleTestPage);
220+
assertThat(driver.getTitle()).isEqualTo("Hello WebDriver");
221+
}
203222
}

java/test/org/openqa/selenium/edge/EdgeDriverFunctionalTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import java.time.Duration;
2828
import java.util.List;
29+
import java.util.Locale;
2930
import java.util.Map;
3031
import org.junit.jupiter.api.Test;
3132
import org.openqa.selenium.Capabilities;
@@ -38,6 +39,7 @@
3839
import org.openqa.selenium.chromium.HasCdp;
3940
import org.openqa.selenium.chromium.HasNetworkConditions;
4041
import org.openqa.selenium.chromium.HasPermissions;
42+
import org.openqa.selenium.net.PortProber;
4143
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
4244
import org.openqa.selenium.remote.http.ClientConfig;
4345
import org.openqa.selenium.testing.Ignore;
@@ -193,4 +195,22 @@ void canExecuteCdpCommands() {
193195

194196
assertThat(driver.getTitle()).isEqualTo("Hello WebDriver");
195197
}
198+
199+
@Test
200+
@NoDriverBeforeTest
201+
void shouldLaunchSuccessfullyWithArabicDate() {
202+
Locale arabicLocale = new Locale("ar", "EG");
203+
Locale.setDefault(arabicLocale);
204+
Locale.setDefault(Locale.US);
205+
206+
int port = PortProber.findFreePort();
207+
EdgeDriverService.Builder builder = new EdgeDriverService.Builder();
208+
builder.usingPort(port);
209+
EdgeDriverService service = builder.build();
210+
211+
driver = new EdgeDriver(service, (EdgeOptions) EDGE.getCapabilities());
212+
213+
driver.get(pages.simpleTestPage);
214+
assertThat(driver.getTitle()).isEqualTo("Hello WebDriver");
215+
}
196216
}

java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.io.IOException;
3838
import java.lang.reflect.Field;
3939
import java.time.Duration;
40+
import java.util.Locale;
4041
import org.junit.jupiter.api.Test;
4142
import org.junit.jupiter.api.Timeout;
4243
import org.mockito.ArgumentMatchers;
@@ -50,6 +51,7 @@
5051
import org.openqa.selenium.PageLoadStrategy;
5152
import org.openqa.selenium.SessionNotCreatedException;
5253
import org.openqa.selenium.WebElement;
54+
import org.openqa.selenium.net.PortProber;
5355
import org.openqa.selenium.remote.CapabilityType;
5456
import org.openqa.selenium.remote.Command;
5557
import org.openqa.selenium.remote.CommandExecutor;
@@ -268,5 +270,22 @@ void canSetContext() {
268270
assertThat(context.getContext()).isEqualTo(FirefoxCommandContext.CHROME);
269271
}
270272

273+
@Test
274+
@NoDriverBeforeTest
275+
void shouldLaunchSuccessfullyWithArabicDate() {
276+
Locale arabicLocale = new Locale("ar", "EG");
277+
Locale.setDefault(arabicLocale);
278+
Locale.setDefault(Locale.US);
279+
280+
int port = PortProber.findFreePort();
281+
GeckoDriverService.Builder builder = new GeckoDriverService.Builder();
282+
builder.usingPort(port);
283+
GeckoDriverService service = builder.build();
284+
285+
driver = new FirefoxDriver(service, (FirefoxOptions) FIREFOX.getCapabilities());
286+
driver.get(pages.simpleTestPage);
287+
assertThat(driver.getTitle()).isEqualTo("Hello WebDriver");
288+
}
289+
271290
private static class CustomFirefoxProfile extends FirefoxProfile {}
272291
}

0 commit comments

Comments
 (0)