[java] Fix 15634/ensure driver closed java by iampopovich ยท Pull Request #16038 ยท SeleniumHQ/selenium
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-catchblock in thestartSessionmethod and the use ofDriverCommandExecutorfor 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
- Bug fix (backwards compatible)
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
flowchart LR
A["Session Creation"] --> B["Try Block"]
B --> C["Execute NEW_SESSION"]
C --> D["Success?"]
D -->|Yes| E["Set Capabilities & SessionId"]
D -->|No| F["Catch Exception"]
F --> G["Check DriverCommandExecutor"]
G --> H["Stop Service"]
H --> I["Throw Original Exception"]
Changes walkthrough ๐
| Relevant files | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Bug fix |
| ||||||||
| Tests |
|
Need help?
Type /help how to ...in the comments thread for any questions about Qodo Merge usage.Check out the documentation for more information.