You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
While reviewing the source code, I noticed that some sections contain unnecessary type conversions in arithmetic operations and string formatting.
Motivation and Context
I made part of these changes with the guidance of IntelliJ IDEA's code inspection. I believe that making such changes will help maintain it in a cleaner and more readable format for future maintenance.
Types of changes
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
2, because the changes are straightforward and mostly involve refactoring and simplification of existing code. The PR modifies type casting, simplifies switch-case statements, and updates some arithmetic operations. These changes are not complex but require careful review to ensure they maintain the same functionality.
🧪 Relevant tests
No
⚡ Possible issues
Possible Bug: The changes in arithmetic operations (e.g., removing division by 1) might alter the behavior if not tested thoroughly. For example, changing redSize.getWidth() / 1 + 1 to redSize.getWidth() + 1 in various tests could potentially lead to different outcomes if the original intent was misunderstood.
Replace String.format with string concatenation for performance improvement.
Replace the use of String.format with direct string concatenation in the toJson method to enhance performance, as String.format can be relatively slower and is not necessary for simple concatenations.
Ensure meaningful output of finders in exception messages.
Ensure that the finders object's toString method provides a meaningful representation of its contents, as it is used in an exception message. If finders is a collection, consider overriding its toString method or using a utility to format its contents more readably.
-throw new IllegalArgumentException(String.format("You must specify at most one location strategy. Number found: %d (%s)", finders.size(), finders));+throw new IllegalArgumentException(String.format("You must specify at most one location strategy. Number found: %d (%s)", finders.size(), finders.toString()));
Add validation for element movement coordinates.
Consider checking the validity of the coordinates before performing the moveToElement operation to ensure they are within the expected range, which could prevent runtime errors or unexpected behavior.
+if (redSize.getWidth() + 1 > someMaxWidth || redSize.getHeight() + 1 > someMaxHeight) throw new IllegalArgumentException("Coordinates are out of bounds.");
.moveToElement(redbox, redSize.getWidth() + 1, redSize.getHeight() + 1)
Properly handle InterruptedException by resetting the interrupt flag.
When catching InterruptedException, it's a good practice to reset the interrupt flag with Thread.currentThread().interrupt(), which allows other methods higher up the call stack to know about the interruption.
* replaced condition controll flow with switch
* remove casting from double to int
division operation with integer ergument is equal to cast to int Math.floor()
* remove division by 1 in tests
* replaced manual calculation of hashcode with Long.hashCode()
* removed redundand toString method call
* removed cast to string in string concat
* applying code formatting
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
While reviewing the source code, I noticed that some sections contain unnecessary type conversions in arithmetic operations and string formatting.
Motivation and Context
I made part of these changes with the guidance of IntelliJ IDEA's code inspection. I believe that making such changes will help maintain it in a cleaner and more readable format for future maintenance.
Types of changes
Checklist
PR Type
enhancement
Description
CdpClientGenerator.java
for cleaner code.toString
calls and simplified exception messages in several test classes.Color.java
usingLong.hashCode
.Changes walkthrough 📝
CdpClientGenerator.java
Refactor Conditional Statements to Switch-Case in toJson Method
java/src/org/openqa/selenium/devtools/CdpClientGenerator.java
handling in
toJson
method.AbstractFindByBuilder.java
Simplify Exception Message Formatting in assertValidFindBy
java/src/org/openqa/selenium/support/AbstractFindByBuilder.java
toString
method call in exception messageformatting.
Color.java
Optimize Hash Code Calculation in Color Class
java/src/org/openqa/selenium/support/Color.java
Long.hashCode
for hash codecalculation.
DefaultMouseTest.java
Remove Redundant Division in Mouse Movement Test
java/test/org/openqa/selenium/bidi/input/DefaultMouseTest.java
DragAndDropTest.java
Simplify Exception Message in DragAndDropTest
java/test/org/openqa/selenium/bidi/input/DragAndDropTest.java
toString
methodcall.
DefaultMouseTest.java
Clean Up Redundant Division in Mouse Interaction Test
java/test/org/openqa/selenium/interactions/DefaultMouseTest.java
PenPointerTest.java
Refactor Pointer Movement Calculations
java/test/org/openqa/selenium/interactions/PenPointerTest.java