selenium
selenium copied to clipboard
[dotnet] Modernize `EnvironmentManager`, standardize assembly teardown
User description
Description
Modernizes some test code and standardizes assembly teardown, in preparation for testing infrastructure improvements.
Motivation and Context
Contributes to https://github.com/SeleniumHQ/selenium/issues/15536
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)
Checklist
- [x] I have read the contributing document.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [x] All new and existing tests passed.
PR Type
Enhancement, Tests
Description
-
Introduced centralized
AssemblyTeardownfor test setup and teardown.- Added
AssemblyTeardownclasses for Chrome, Edge, Firefox, IE, Safari, and Remote tests. - Unified test environment initialization and cleanup logic.
- Added
-
Refactored
EnvironmentManagerfor improved readability and immutability.- Converted mutable fields to readonly properties where applicable.
- Simplified singleton implementation for
EnvironmentManager.
-
Modernized test utilities and attributes for better maintainability.
- Replaced manual property definitions with auto-properties.
- Simplified type checks and casting in
NeedsFreshDriverAttributeandTestUtilities.
-
Reactivated and updated previously commented-out Firefox tests.
- Enabled and adjusted tests in
FirefoxProfileManagerTestandFirefoxProfileTests.
- Enabled and adjusted tests in
Changes walkthrough 📝
| Relevant files | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Enhancement | 12 files
| ||||||||||||||||||||||||
| 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.
PR Reviewer Guide 🔍
Here are some key observations to aid the review process:
|
🎫 Ticket compliance analysis 🔶 15536 - Partially compliant Compliant requirements: • Avoid static context in EnvironmentManager (partially addressed by making properties readonly and improving singleton implementation) Non-compliant requirements: • Consolidate test projects (no changes to merge test projects) • Fix namespace issues (namespace structure remains unchanged) Requires further human verification: • Verify if the changes actually improve parallelization capabilities • Check if the modernized code structure allows for better test execution performance |
| ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪ |
| 🧪 No relevant tests |
| 🔒 No security concerns identified |
⚡ Recommended focus areas for reviewIncomplete Refactoring
|
PR Code Suggestions ✨
Explore these optional code suggestions:
| Category | Suggestion | Impact |
| Possible issue |
Close driver before creating newThe method creates a fresh driver but doesn't properly clean up the previous dotnet/test/common/CustomTestAttributes/NeedsFreshDriverAttribute.cs [43-52]
Suggestion importance[1-10]: 9__ Why: Not closing the previous driver before creating a new one will cause resource leaks as browser instances remain open. This can significantly impact system resources during test runs. | High |
Avoid blocking in finalizerThe finalizer is blocking on asynchronous operations which can lead to deadlocks dotnet/test/common/Environment/EnvironmentManager.cs [193-198]
Suggestion importance[1-10]: 8__ Why: Blocking on async operations in finalizers is a serious issue that can lead to deadlocks or application hangs. Finalizers run on a special thread and should complete quickly without blocking operations. | Medium | |
Use safe castingDirect casting with dotnet/test/common/TestUtilities.cs [26-29]
Suggestion importance[1-10]: 7__ Why: Direct casting with parentheses will throw an InvalidCastException if the driver doesn't implement IJavaScriptExecutor. Using the 'as' operator with null check provides safer type conversion with proper error handling. | Medium | |
| ||
@nvborisenko What do you think? This modernization should have no behavior changes, and it will allow us to iterate on our testing without adding a million lines which change nothing.