Open iampopovich opened 4 weeks ago
⏱️ Estimated effort to review [1-5] | 2, because the PR involves a straightforward addition of a new constructor to handle custom durations in the Actions class. The changes are localized and do not involve complex logic changes. |
🧪 Relevant tests | No |
⚡ Possible issues | Missing Initialization: The new field `actionDuration` is not initialized in the original constructor, which might lead to null issues if methods relying on this field are called without using the new constructor. |
🔒 Security concerns | No |
Category | Suggestion | Score |
Possible issue |
Initialize the new variable in all constructors to prevent potential null pointer issues___ **Ensure thatactionDuration is also initialized in the existing constructor to avoid potential NullPointerException when the duration is used in other methods.**
[java/src/org/openqa/selenium/interactions/Actions.java [60-61]](https://github.com/SeleniumHQ/selenium/pull/14085/files#diff-be22ba4639c55728723af6e60493d4bb5dfa2d9bab9d35e2fc2ba3b9076cc596R60-R61)
```diff
this.driver = Require.nonNull("Driver", driver);
+this.actionDuration = Duration.ofMillis(0); // or any default value
```
Suggestion importance[1-10]: 8Why: This is a crucial suggestion to prevent potential runtime errors due to uninitialized `actionDuration` in the existing constructor. | 8 |
Best practice |
Add validation for the new constructor parameter to ensure it is not null___ **Validate theduration parameter in the new constructor to ensure it is not null, similar to how the driver parameter is validated.**
[java/src/org/openqa/selenium/interactions/Actions.java [64-65]](https://github.com/SeleniumHQ/selenium/pull/14085/files#diff-be22ba4639c55728723af6e60493d4bb5dfa2d9bab9d35e2fc2ba3b9076cc596R64-R65)
```diff
this.driver = Require.nonNull("Driver", driver);
-this.actionDuration = duration;
+this.actionDuration = Require.nonNull("Duration", duration);
```
Suggestion importance[1-10]: 7Why: Validating the `duration` parameter for null values is important for robustness, similar to the existing validation for the `driver` parameter. | 7 |
Maintainability |
Use constructor overloading to avoid code duplication and improve readability___ **To improve code readability, consider overloading the existing constructor instead ofduplicating the code.** [java/src/org/openqa/selenium/interactions/Actions.java [63-66]](https://github.com/SeleniumHQ/selenium/pull/14085/files#diff-be22ba4639c55728723af6e60493d4bb5dfa2d9bab9d35e2fc2ba3b9076cc596R63-R66) ```diff public Actions(WebDriver driver, Duration duration) { - this.driver = Require.nonNull("Driver", driver); + this(driver); // Call the existing constructor this.actionDuration = duration; } ``` Suggestion importance[1-10]: 7Why: Overloading the constructor to reuse existing code improves maintainability and reduces the risk of future errors in constructor logic. | 7 |
Enhancement |
Add a default value for the new parameter to handle null values gracefully___ **Consider adding a default value foractionDuration in the new constructor if duration is null, to provide a fallback mechanism.** [java/src/org/openqa/selenium/interactions/Actions.java [64-65]](https://github.com/SeleniumHQ/selenium/pull/14085/files#diff-be22ba4639c55728723af6e60493d4bb5dfa2d9bab9d35e2fc2ba3b9076cc596R64-R65) ```diff this.driver = Require.nonNull("Driver", driver); -this.actionDuration = duration; +this.actionDuration = (duration != null) ? duration : Duration.ofMillis(0); // or any default value ``` Suggestion importance[1-10]: 6Why: Providing a default value for `actionDuration` if `duration` is null is a good enhancement for better fault tolerance. | 6 |
Oh, thanks for taking on this one! I'm glad someone is finally looking into it.
Your code doesn't actually show actionDuration
getting used anywhere, though? Need to make it so that the default is overridden and used in necessary places.
Please add tests for the new constructor added.
@pujagani I reused two existing tests for the scrollToElement and scrollByAmount methods with a custom Duration. Additionally, I wrote two tests to check the setting of the default Duration and the custom Duration. Will this be enough?
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 57.76%. Comparing base (
5c5487f
) to head (0ef4c94
). Report is 8 commits behind head on trunk.:exclamation: Current head 0ef4c94 differs from pull request most recent head f090146
Please upload reports for the commit f090146 to get more accurate results.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Haven't looked at the failures, pushing this one back to the next release
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
according to #12118 feature request, I started to discover the best way to implement duration overriding
Motivation and Context
Types of changes
Checklist
PR Type
Enhancement
Description
Actions
class in Selenium that allows specifying a customDuration
for actions.actionDuration
to store the specified duration.Changes walkthrough 📝
Actions.java
Add constructor with custom duration to Actions class
java/src/org/openqa/selenium/interactions/Actions.java
Actions
class that accepts aDuration
parameter.
actionDuration
to store theduration.