[java] Fix 15634/ensure driver closed java #16038
Open
+156
−33
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
🔗 Related Issues
partially fixes #15634 for java
💥 What does this PR do?
similar changes as for python in #15636
🔧 Implementation Notes
This pull request enhances the robustness of driver service management in Selenium by ensuring services are properly stopped when session creation fails. It also introduces unit tests across multiple browser drivers to validate this behavior. The most important changes include updates to
RemoteWebDriver
for cleanup logic and new tests for driver service cleanup across Chrome, Edge, Firefox, and Safari.Driver Service Cleanup Enhancements:
java/src/org/openqa/selenium/remote/RemoteWebDriver.java
: Added logic to stop the driver service if session creation fails, preventing zombie processes. This includes atry-catch
block in thestartSession
method and the use ofDriverCommandExecutor
for cleanup. [1] [2]Unit Tests for Driver Service Cleanup:
java/test/org/openqa/selenium/chrome/ChromeDriverServiceCleanupTest.java
: Added a test to verify that the Chrome driver service stops when session creation fails due to invalid options.java/test/org/openqa/selenium/edge/EdgeDriverServiceTest.java
: Added a test to ensure the Edge driver service stops when session creation fails due to invalid options.java/test/org/openqa/selenium/firefox/GeckoDriverServiceTest.java
: Added a test to confirm that the Firefox driver service stops when session creation fails due to an invalid binary path.java/test/org/openqa/selenium/safari/SafariDriverServiceTest.java
: Added a test to verify that the Safari driver service stops when session creation fails due to invalid capabilities.💡 Additional Considerations
🔄 Types of changes
PR Type
Bug fix, Tests
Description
Fix driver service cleanup when session creation fails
Add unit tests for service cleanup across Chrome, Edge, Firefox, Safari
Prevent zombie processes by stopping services on session failure
Enhance error handling in RemoteWebDriver session initialization
Changes diagram
Changes walkthrough 📝
RemoteWebDriver.java
Add session failure cleanup logic
java/src/org/openqa/selenium/remote/RemoteWebDriver.java
ChromeDriverServiceCleanupTest.java
Add Chrome service cleanup test
java/test/org/openqa/selenium/chrome/ChromeDriverServiceCleanupTest.java
EdgeDriverServiceTest.java
Add Edge service cleanup test
java/test/org/openqa/selenium/edge/EdgeDriverServiceTest.java
GeckoDriverServiceTest.java
Add Firefox service cleanup test
java/test/org/openqa/selenium/firefox/GeckoDriverServiceTest.java
SafariDriverServiceTest.java
Add Safari service cleanup test
java/test/org/openqa/selenium/safari/SafariDriverServiceTest.java