[Java] Add Locale.ROOT to avoid port formatting issues for all drivers#15121
[Java] Add Locale.ROOT to avoid port formatting issues for all drivers#15121pujagani merged 6 commits intoSeleniumHQ:trunkfrom MustafaAgamy:trunk
Conversation
- ChromeDriverService - EdgeDriverService - GeckoDriverService - InternetExplorerDriverService and to the getUrl method at: - DriverService Refactor the Arabic Tests in the following accordingly: - ChromeDriverFunctionalTest - EdgeDriverFunctionalTest - FirefoxDriverTest - InternetExplorerDriverTest - SafariDriverTest
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
@nvborisenko as discussed, please check. |
You can see the old tests refactored to comply with the current changes so I didn't have to actually create "New" tests @nvborisenko |
|
LGTM. Thank you @MustafaAgamy! Will merge once the CI runs successfully. |
|
|
||
| Locale.setDefault(Locale.US); | ||
| } catch (Exception e) { | ||
| throw e; |
There was a problem hiding this comment.
Why do we need this "catch+throw" block?
It should be removed.
There was a problem hiding this comment.
It's needed In case the test failed for any reason then we will throw the exception and at the finally block we will revert the locale default back to English regardless
That's why it's following
Try-catch with finally
There was a problem hiding this comment.
@MustafaAgamy In this case, please use try { ... } finally { ... }. The "catch" part is not needed.
It doesn't make sense to catch and throw an exception without handling it.
| void shouldThrowNumberFormatException() { | ||
| Locale arabicLocale = new Locale("ar", "EG"); | ||
| Locale.setDefault(arabicLocale); | ||
| void shouldLaunchSuccessfullyWithArabicDate() { |
There was a problem hiding this comment.
I this this test is not needed at all.
It should be removed.
There was a problem hiding this comment.
As disccussed earlier this test is using arabic as a unit test for port formatting logic
There was a problem hiding this comment.
@MustafaAgamy
The line Locale.setDefault(arabicLocale) changes the global JVM state which may affect other tests (especially when they are running in parallel).
This test only checks that ChromeDriverService.Builder works with Arabic locale.
Why only this class?
Actually, we need to check that the whole Selenium Webdriver works with Arabic locale.
Instead of this single test, we should run ALL tests with Arabic locale.
For example, in Selenide we run all tests with Turkish locale for the same reason:
tasks.withType(Test).configureEach {
useJUnitPlatform()
systemProperties['user.country'] = 'TR'
systemProperties['user.language'] = 'tr'There was a problem hiding this comment.
So what's the suggestion here?
Have some kind of Environement Properties set to run all tests with Arabic language?
You see, the thing is you don't actually need to run all tests against arabic. You just need to test if the builder will be able to build the driver instance successfully while the System language is arabic, that's pretty much it (That's the AOI - Area of Impact - for this unit test)
There was a problem hiding this comment.
We don't even need any environment variables. We can just add these parameters to Bazel script to always run tests with Arabic locale.
(There is a more complex option - run tests with multiple "special" locales: Arabic, Turkish etc. But it's probably overkill.)
P.S. Yes, I see this is AOI of this test. And this is the wrong AOI.
SeleniumHQ#15121) Co-authored-by: Puja Jagani <[email protected]>
SeleniumHQ#15121) Co-authored-by: Puja Jagani <[email protected]>
User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
Added the Locale.ROOT for port formatting to avoid any issues when starting the driver session
Motivation and Context
To Avoid port formatting issues against different languages
Types of changes
Checklist
PR Type
Bug fix, Tests
Description
Added
Locale.ROOTto ensure consistent port formatting across all driver services.Updated
getUrlmethod inDriverServiceto useLocale.ROOT.Refactored tests to validate successful driver launches with Arabic locale.
Removed outdated exception handling for Arabic locale in driver services.
Changes walkthrough 📝
5 files
Use `Locale.ROOT` for port formatting in ChromeDriverServiceUse `Locale.ROOT` for port formatting in EdgeDriverServiceUse `Locale.ROOT` for port formatting in GeckoDriverServiceUseLocale.ROOTfor port formatting in InternetExplorerDriverServiceApplyLocale.ROOTtogetUrlmethod and remove Arabic locale exception5 files
Refactor test to validate Arabic locale compatibility for ChromeDriverRefactor test to validate Arabic locale compatibility for EdgeDriverRefactor test to validate Arabic locale compatibility forFirefoxDriverRefactor test to validate Arabic locale compatibility for IEDriverRefactor test to validate Arabic locale compatibility for SafariDriver