Skip to content

[dotnet] [test] Driver is protected through fixtures#17726

Merged
nvborisenko merged 1 commit into
SeleniumHQ:trunkfrom
nvborisenko:dotnet-test-driver-protected
Jun 28, 2026
Merged

[dotnet] [test] Driver is protected through fixtures#17726
nvborisenko merged 1 commit into
SeleniumHQ:trunkfrom
nvborisenko:dotnet-test-driver-protected

Conversation

@nvborisenko

Copy link
Copy Markdown
Member

OOP.

🔗 Related Issues

Contributes to #15536

💥 What does this PR do?

Protected Driver

🤖 AI assistance

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s):
    • What was generated:
    • I reviewed all AI output and can explain the change

💡 Additional Considerations

🔄 Types of changes

  • Cleanup (formatting, renaming)

@selenium-ci selenium-ci added C-dotnet .NET Bindings B-support Issue or PR related to support classes labels Jun 28, 2026
@selenium-ci

Copy link
Copy Markdown
Member

Thank you, @nvborisenko for this code suggestion.

The support packages contain example code that many users find helpful, but they do not necessarily represent
the best practices for using Selenium, and the Selenium team is not currently merging changes to them.

After reviewing the change, unless it is a critical fix or a feature that is needed for Selenium
to work, we will likely close the PR.

We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks.
If you have any questions, please contact us

@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

[dotnet][test] Encapsulate IWebDriver via protected fixture property
🧪 Tests ✨ Enhancement 🕐 20-40 Minutes

Grey Divider

Description

• Make the test fixture WebDriver property protected to reduce direct external mutation.
• Update all .NET tests to use Driver instead of the public driver member.
• Align driver lifecycle hooks (fresh driver + DevTools fixture) with the new property.
Diagram

graph TD
  A["NUnit tests"] --> B["DriverTestFixture"] --> C["EnvironmentManager"] --> D[("IWebDriver")]
  E["NeedsFreshDriver"] --> C --> D
  E --> B
  F["DevToolsFixture"] --> B
  F --> G["IDevTools"]

  subgraph Legend
    direction LR
    _t["Test"] ~~~ _f["Fixture"] ~~~ _a["Attribute"] ~~~ _e["Env mgr"] ~~~ _d[("Driver")] 
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Expose `protected IWebDriver Driver { get; private set; }`
  • ➕ Stronger encapsulation (no external setter)
  • ➕ Forces lifecycle changes through fixture methods, reducing accidental reassignment
  • ➖ May require refactoring attribute-based reassignment (e.g., NeedsFreshDriver) into a fixture method
  • ➖ Slightly more intrusive change than a rename
2. Keep `Driver` public but mark `driver` obsolete
  • ➕ Less churn in existing tests; gradual migration
  • ➕ External consumers can continue compiling temporarily
  • ➖ Does not fully enforce encapsulation goal
  • ➖ Extends the migration window and keeps foot-guns around
3. Provide `ResetDriver()`/`WithFreshDriver()` API instead of direct property writes
  • ➕ Clear, explicit lifecycle semantics
  • ➕ Centralizes disposal/creation logic and reduces duplicated patterns
  • ➖ Requires updating attribute + any fixtures that currently set the property directly
  • ➖ More code than a straightforward access-level change

Recommendation: The PR’s approach (rename to Driver and restrict access via the base fixture) is a good incremental step: it reduces accidental direct access while keeping the driver lifecycle mechanics intact. If further hardening is desired, consider following up by making the setter private and routing fresh-driver behavior through an explicit fixture method (or a small internal interface) to avoid direct reassignment from attributes.

Files changed (78) +3052 / -3052

Refactor (78) +3052 / -3052
RemoteWebDriverSpecificTests.csSwitch RemoteWebDriver tests to fixture 'Driver' +10/-10

Switch RemoteWebDriver tests to fixture 'Driver'

• Replaces direct 'driver' usage with 'Driver' from the base fixture when interacting with remote capabilities and file upload flow.

dotnet/test/remote/RemoteWebDriverSpecificTests.cs

EventFiringWebDriverElementTests.csUse fixture 'Driver' in EventFiring element tests +2/-2

Use fixture 'Driver' in EventFiring element tests

• Updates setup/navigation and EventFiringWebDriver construction to use 'Driver' instead of a public driver field.

dotnet/test/support/Events/EventFiringWebDriverElementTests.cs

PopupWindowFinderTests.csUse fixture 'Driver' in popup window tests +30/-30

Use fixture 'Driver' in popup window tests

• Routes all navigation, window-handle switching, and PopupWindowFinder usage through 'Driver'.

dotnet/test/support/UI/PopupWindowFinderTests.cs

SelectBrowserTests.csUse fixture 'Driver' in SelectBrowser tests +36/-36

Use fixture 'Driver' in SelectBrowser tests

• Replaces direct driver access with 'Driver' for navigation and element interactions in select-related tests.

dotnet/test/support/UI/SelectBrowserTests.cs

AlertsTests.csUse fixture 'Driver' in alert/prompt tests +83/-83

Use fixture 'Driver' in alert/prompt tests

• Updates navigation, script execution, element clicks, and assertions to reference 'Driver' rather than 'driver'.

dotnet/test/webdriver/AlertsTests.cs

ChildrenFindingTests.csUse fixture 'Driver' in child element finding tests +71/-71

Use fixture 'Driver' in child element finding tests

• Replaces direct driver calls with 'Driver' for locating elements and validating child search behavior.

dotnet/test/webdriver/ChildrenFindingTests.cs

ClearTests.csUse fixture 'Driver' in element clear tests +16/-16

Use fixture 'Driver' in element clear tests

• Updates element lookup and state assertions to use 'Driver' from the fixture.

dotnet/test/webdriver/ClearTests.cs

ClickScrollingTests.csUse fixture 'Driver' in click/scrolling tests +57/-57

Use fixture 'Driver' in click/scrolling tests

• Switches navigation and interaction steps to use the encapsulated 'Driver' property.

dotnet/test/webdriver/ClickScrollingTests.cs

ClickTests.csUse fixture 'Driver' in click interaction tests +108/-108

Use fixture 'Driver' in click interaction tests

• Replaces extensive direct driver usage with 'Driver' across navigation, frame switching, JS execution, and assertions.

dotnet/test/webdriver/ClickTests.cs

ContentEditableTests.csUse fixture 'Driver' in contenteditable tests +22/-22

Use fixture 'Driver' in contenteditable tests

• Updates navigation and element operations to use 'Driver'.

dotnet/test/webdriver/ContentEditableTests.cs

CookieImplementationTests.csUse fixture 'Driver' in cookie tests +112/-112

Use fixture 'Driver' in cookie tests

• Refactors cookie creation/retrieval/deletion flows to reference 'Driver' consistently.

dotnet/test/webdriver/CookieImplementationTests.cs

CorrectEventFiringTests.csUse fixture 'Driver' in event firing correctness tests +113/-113

Use fixture 'Driver' in event firing correctness tests

• Replaces direct driver access with 'Driver' for event registration, navigation, and element interaction checks.

dotnet/test/webdriver/CorrectEventFiringTests.cs

CssValueTests.csUse fixture 'Driver' in CSS value tests +8/-8

Use fixture 'Driver' in CSS value tests

• Updates element queries and assertions to use 'Driver'.

dotnet/test/webdriver/CssValueTests.cs

DevToolsConsoleTests.csUse fixture 'Driver' in DevTools console tests +2/-2

Use fixture 'Driver' in DevTools console tests

• Replaces direct driver references with 'Driver' in DevTools-related test logic.

dotnet/test/webdriver/DevTools/DevToolsConsoleTests.cs

DevToolsLogTests.csUse fixture 'Driver' in DevTools log tests +1/-1

Use fixture 'Driver' in DevTools log tests

• Routes driver usage through the 'Driver' property.

dotnet/test/webdriver/DevTools/DevToolsLogTests.cs

DevToolsNetworkTests.csUse fixture 'Driver' in DevTools network tests +14/-14

Use fixture 'Driver' in DevTools network tests

• Updates driver access patterns to use 'Driver' for network event and interception flows.

dotnet/test/webdriver/DevTools/DevToolsNetworkTests.cs

DevToolsPerformanceTests.csUse fixture 'Driver' in DevTools performance tests +6/-6

Use fixture 'Driver' in DevTools performance tests

• Switches direct driver usage to the fixture 'Driver' property.

dotnet/test/webdriver/DevTools/DevToolsPerformanceTests.cs

DevToolsProfilerTests.csUse fixture 'Driver' in DevTools profiler tests +4/-4

Use fixture 'Driver' in DevTools profiler tests

• Replaces direct driver references with 'Driver'.

dotnet/test/webdriver/DevTools/DevToolsProfilerTests.cs

DevToolsSecurityTests.csUse fixture 'Driver' in DevTools security tests +4/-4

Use fixture 'Driver' in DevTools security tests

• Updates driver interactions to use the encapsulated 'Driver'.

dotnet/test/webdriver/DevTools/DevToolsSecurityTests.cs

DevToolsTabsTests.csUse fixture 'Driver' in DevTools tabs tests +4/-4

Use fixture 'Driver' in DevTools tabs tests

• Routes DevTools tab operations through 'Driver'.

dotnet/test/webdriver/DevTools/DevToolsTabsTests.cs

DevToolsTargetTests.csUse fixture 'Driver' in DevTools target tests +2/-2

Use fixture 'Driver' in DevTools target tests

• Refactors driver access to use 'Driver'.

dotnet/test/webdriver/DevTools/DevToolsTargetTests.cs

DevToolsTestFixture.csEncapsulate driver handling in DevTools fixture +3/-3

Encapsulate driver handling in DevTools fixture

• Updates DevToolsTestFixture to assign/cast via 'Driver' and to clear 'Driver' during teardown.

dotnet/test/webdriver/DevTools/DevToolsTestFixture.cs

DownloadsTests.csUse fixture 'Driver' in download tests +8/-8

Use fixture 'Driver' in download tests

• Replaces direct driver usage with 'Driver' in navigation and download verification code paths.

dotnet/test/webdriver/DownloadsTests.cs

DriverElementFindingTests.csUse fixture 'Driver' in driver-level element finding tests +28/-28

Use fixture 'Driver' in driver-level element finding tests

• Updates element finding calls to use 'Driver' instead of the old public member.

dotnet/test/webdriver/DriverElementFindingTests.cs

DriverTestFixture.csMake WebDriver protected via 'Driver' property +8/-8

Make WebDriver protected via 'Driver' property

• Replaces the public 'driver' property with 'protected internal IWebDriver Driver' and updates setup/teardown/wait helpers to use it.

dotnet/test/webdriver/DriverTestFixture.cs

ElementAttributeTests.csUse fixture 'Driver' in element attribute tests +92/-92

Use fixture 'Driver' in element attribute tests

• Refactors navigation and attribute assertions to reference 'Driver'.

dotnet/test/webdriver/ElementAttributeTests.cs

ElementElementFindingTests.csUse fixture 'Driver' in element-scoped finding tests +28/-28

Use fixture 'Driver' in element-scoped finding tests

• Switches direct driver usage to 'Driver' for finding nested elements and verifying behaviors.

dotnet/test/webdriver/ElementElementFindingTests.cs

ElementEqualityTests.csUse fixture 'Driver' in element equality tests +15/-15

Use fixture 'Driver' in element equality tests

• Updates element lookups and equality assertions to use 'Driver'.

dotnet/test/webdriver/ElementEqualityTests.cs

ElementFindingTests.csUse fixture 'Driver' in element finding tests +245/-245

Use fixture 'Driver' in element finding tests

• Replaces extensive direct driver calls with 'Driver' for locating elements and validating selector behaviors.

dotnet/test/webdriver/ElementFindingTests.cs

ElementPropertyTests.csUse fixture 'Driver' in element property tests +4/-4

Use fixture 'Driver' in element property tests

• Refactors property checks to use 'Driver'.

dotnet/test/webdriver/ElementPropertyTests.cs

ElementSelectingTests.csUse fixture 'Driver' in element selection tests +28/-28

Use fixture 'Driver' in element selection tests

• Updates selection interactions to use 'Driver'.

dotnet/test/webdriver/ElementSelectingTests.cs

ErrorsTests.csUse fixture 'Driver' in error handling tests +2/-2

Use fixture 'Driver' in error handling tests

• Replaces direct driver references with 'Driver' in negative/exception scenarios.

dotnet/test/webdriver/ErrorsTests.cs

ExecutingAsyncJavascriptTests.csUse fixture 'Driver' in async JS execution tests +59/-59

Use fixture 'Driver' in async JS execution tests

• Refactors JS execution and assertions to use 'Driver'.

dotnet/test/webdriver/ExecutingAsyncJavascriptTests.cs

ExecutingJavascriptTests.csUse fixture 'Driver' in JS execution tests +116/-116

Use fixture 'Driver' in JS execution tests

• Updates JS execution and navigation to reference 'Driver' consistently.

dotnet/test/webdriver/ExecutingJavascriptTests.cs

FirefoxDriverTests.csUse fixture 'Driver' in Firefox-specific tests +52/-52

Use fixture 'Driver' in Firefox-specific tests

• Switches Firefox tests to use 'Driver' for navigation, capability checks, and interactions.

dotnet/test/webdriver/Firefox/FirefoxDriverTests.cs

FormHandlingTests.csUse fixture 'Driver' in form handling tests +73/-73

Use fixture 'Driver' in form handling tests

• Replaces direct driver access with 'Driver' across form fill/submit and assertion flows.

dotnet/test/webdriver/FormHandlingTests.cs

FrameSwitchingTests.csUse fixture 'Driver' in frame switching tests +179/-179

Use fixture 'Driver' in frame switching tests

• Updates all frame/window switching, navigation, and assertions to use 'Driver'.

dotnet/test/webdriver/FrameSwitchingTests.cs

GetLogsTests.csUse fixture 'Driver' in log retrieval tests +9/-9

Use fixture 'Driver' in log retrieval tests

• Routes log access and assertions through 'Driver'.

dotnet/test/webdriver/GetLogsTests.cs

GetMultipleAttributeTests.csUse fixture 'Driver' in multi-attribute retrieval tests +10/-10

Use fixture 'Driver' in multi-attribute retrieval tests

• Updates element lookup and attribute retrieval to use 'Driver'.

dotnet/test/webdriver/GetMultipleAttributeTests.cs

I18Tests.csUse fixture 'Driver' in i18n tests +11/-11

Use fixture 'Driver' in i18n tests

• Switches navigation and assertions to use 'Driver'.

dotnet/test/webdriver/I18Tests.cs

IeSpecificTests.csUse fixture 'Driver' in IE-specific tests +90/-90

Use fixture 'Driver' in IE-specific tests

• Refactors IE-specific test interactions to use the fixture 'Driver' property.

dotnet/test/webdriver/IE/IeSpecificTests.cs

ImplicitWaitTests.csUse fixture 'Driver' in implicit wait tests +37/-37

Use fixture 'Driver' in implicit wait tests

• Updates timeouts, navigation, and element operations to reference 'Driver'.

dotnet/test/webdriver/ImplicitWaitTests.cs

NeedsFreshDriverAttribute.csUpdate fresh-driver attribute to set 'fixtureInstance.Driver' +2/-2

Update fresh-driver attribute to set 'fixtureInstance.Driver'

• Replaces direct assignment to the old 'driver' member with assignment to the protected 'Driver' property when recreating drivers.

dotnet/test/webdriver/Infrastructure/NeedsFreshDriverAttribute.cs

BasicKeyboardInterfaceTests.csUse fixture 'Driver' in keyboard interaction tests +56/-56

Use fixture 'Driver' in keyboard interaction tests

• Refactors keyboard-related navigation and actions to use 'Driver'.

dotnet/test/webdriver/Interactions/BasicKeyboardInterfaceTests.cs

BasicMouseInterfaceTests.csUse fixture 'Driver' in mouse interaction tests +103/-103

Use fixture 'Driver' in mouse interaction tests

• Updates mouse action tests to use 'Driver' for element interactions and assertions.

dotnet/test/webdriver/Interactions/BasicMouseInterfaceTests.cs

BasicWheelInterfaceTests.csUse fixture 'Driver' in wheel interaction tests +35/-35

Use fixture 'Driver' in wheel interaction tests

• Switches wheel/scroll action tests to use 'Driver'.

dotnet/test/webdriver/Interactions/BasicWheelInterfaceTests.cs

CombinedInputActionsTests.csUse fixture 'Driver' in combined input action tests +95/-95

Use fixture 'Driver' in combined input action tests

• Refactors combined input action flows to reference 'Driver'.

dotnet/test/webdriver/Interactions/CombinedInputActionsTests.cs

DragAndDropTests.csUse fixture 'Driver' in drag-and-drop tests +49/-49

Use fixture 'Driver' in drag-and-drop tests

• Updates action builder usage and assertions to use 'Driver'.

dotnet/test/webdriver/Interactions/DragAndDropTests.cs

JavascriptEnabledBrowserTests.csUse fixture 'Driver' in JS-enabled browser tests +53/-53

Use fixture 'Driver' in JS-enabled browser tests

• Switches script execution and navigation to use 'Driver'.

dotnet/test/webdriver/JavascriptEnabledBrowserTests.cs

MiscTests.csUse fixture 'Driver' in miscellaneous tests +20/-20

Use fixture 'Driver' in miscellaneous tests

• Refactors various navigation and driver capability checks to use 'Driver'.

dotnet/test/webdriver/MiscTests.cs

NavigationTests.csUse fixture 'Driver' in navigation tests +34/-34

Use fixture 'Driver' in navigation tests

• Replaces direct driver usage with 'Driver' for back/forward/refresh and related assertions.

dotnet/test/webdriver/NavigationTests.cs

NetworkInterceptionTests.csUse fixture 'Driver' in network interception tests +16/-16

Use fixture 'Driver' in network interception tests

• Routes navigation and interception-related calls through 'Driver'.

dotnet/test/webdriver/NetworkInterceptionTests.cs

ObjectStateAssumptionsTests.csUse fixture 'Driver' in object state assumption tests +7/-7

Use fixture 'Driver' in object state assumption tests

• Updates assumptions and interactions to use 'Driver'.

dotnet/test/webdriver/ObjectStateAssumptionsTests.cs

PageLoadingTests.csUse fixture 'Driver' in page loading tests +71/-71

Use fixture 'Driver' in page loading tests

• Refactors page load timing/behavior tests to reference 'Driver' consistently.

dotnet/test/webdriver/PageLoadingTests.cs

PartialLinkTextMatchTests.csUse fixture 'Driver' in partial link text tests +12/-12

Use fixture 'Driver' in partial link text tests

• Updates link lookup and assertions to use 'Driver'.

dotnet/test/webdriver/PartialLinkTextMatchTests.cs

PositionAndSizeTests.csUse fixture 'Driver' in position/size tests +27/-27

Use fixture 'Driver' in position/size tests

• Replaces direct driver and element queries with 'Driver' usage.

dotnet/test/webdriver/PositionAndSizeTests.cs

PrintTests.csUse fixture 'Driver' in print tests +3/-3

Use fixture 'Driver' in print tests

• Updates print-related calls to reference 'Driver'.

dotnet/test/webdriver/PrintTests.cs

ProxySettingTests.csUse fixture 'Driver' in proxy setting tests +2/-2

Use fixture 'Driver' in proxy setting tests

• Refactors proxy-related checks to use 'Driver'.

dotnet/test/webdriver/ProxySettingTests.cs

RelativeLocatorTests.csUse fixture 'Driver' in relative locator tests +34/-34

Use fixture 'Driver' in relative locator tests

• Switches element location flows to use 'Driver'.

dotnet/test/webdriver/RelativeLocatorTests.cs

SelectElementHandlingTests.csUse fixture 'Driver' in select element handling tests +25/-25

Use fixture 'Driver' in select element handling tests

• Updates select element interactions to use 'Driver'.

dotnet/test/webdriver/SelectElementHandlingTests.cs

SessionHandlingTests.csUse fixture 'Driver' in session handling tests +8/-8

Use fixture 'Driver' in session handling tests

• Refactors session operations and assertions to reference 'Driver'.

dotnet/test/webdriver/SessionHandlingTests.cs

ShadowRootHandlingTests.csUse fixture 'Driver' in shadow root handling tests +12/-12

Use fixture 'Driver' in shadow root handling tests

• Updates shadow DOM interactions to use 'Driver'.

dotnet/test/webdriver/ShadowRootHandlingTests.cs

SlowLoadingPageTests.csUse fixture 'Driver' in slow loading page tests +4/-4

Use fixture 'Driver' in slow loading page tests

• Switches navigation and waits to use 'Driver'.

dotnet/test/webdriver/SlowLoadingPageTests.cs

StaleElementReferenceTests.csUse fixture 'Driver' in stale element reference tests +12/-12

Use fixture 'Driver' in stale element reference tests

• Updates stale-element scenarios to use 'Driver' consistently.

dotnet/test/webdriver/StaleElementReferenceTests.cs

SvgDocumentTests.csUse fixture 'Driver' in SVG document tests +7/-7

Use fixture 'Driver' in SVG document tests

• Refactors navigation and element access to use 'Driver'.

dotnet/test/webdriver/SvgDocumentTests.cs

SvgElementTests.csUse fixture 'Driver' in SVG element tests +9/-9

Use fixture 'Driver' in SVG element tests

• Updates SVG element interactions to reference 'Driver'.

dotnet/test/webdriver/SvgElementTests.cs

TagNameTests.csUse fixture 'Driver' in tag name tests +2/-2

Use fixture 'Driver' in tag name tests

• Switches element lookup to use 'Driver'.

dotnet/test/webdriver/TagNameTests.cs

TakesScreenshotTests.csUse fixture 'Driver' in screenshot tests +33/-33

Use fixture 'Driver' in screenshot tests

• Updates screenshot capture flows to use 'Driver' for navigation and element/driver screenshot assertions.

dotnet/test/webdriver/TakesScreenshotTests.cs

TargetLocatorTests.csUse fixture 'Driver' in target locator tests +34/-34

Use fixture 'Driver' in target locator tests

• Replaces direct driver switching/targeting calls with 'Driver' usage.

dotnet/test/webdriver/TargetLocatorTests.cs

TextHandlingTests.csUse fixture 'Driver' in text handling tests +83/-83

Use fixture 'Driver' in text handling tests

• Refactors text input, retrieval, and assertions to use 'Driver'.

dotnet/test/webdriver/TextHandlingTests.cs

TextPagesTests.csUse fixture 'Driver' in text page tests +6/-6

Use fixture 'Driver' in text page tests

• Updates navigation and assertions to use 'Driver'.

dotnet/test/webdriver/TextPagesTests.cs

TypingTests.csUse fixture 'Driver' in typing tests +119/-119

Use fixture 'Driver' in typing tests

• Replaces direct driver usage with 'Driver' across typing scenarios, element lookup, and assertions.

dotnet/test/webdriver/TypingTests.cs

UploadTests.csUse fixture 'Driver' in upload tests +27/-27

Use fixture 'Driver' in upload tests

• Switches file input interactions and post-upload assertions to use 'Driver'.

dotnet/test/webdriver/UploadTests.cs

VirtualAuthenticatorTests.csUse fixture 'Driver' in virtual authenticator tests +2/-2

Use fixture 'Driver' in virtual authenticator tests

• Updates authenticator setup and driver interactions to reference 'Driver'.

dotnet/test/webdriver/VirtualAuthn/VirtualAuthenticatorTests.cs

VisibilityTests.csUse fixture 'Driver' in visibility tests +52/-52

Use fixture 'Driver' in visibility tests

• Refactors visibility checks and navigation to use 'Driver'.

dotnet/test/webdriver/VisibilityTests.cs

WebElementTests.csUse fixture 'Driver' in WebElement tests +33/-33

Use fixture 'Driver' in WebElement tests

• Updates core WebElement interaction tests to use 'Driver' for element lookup and assertions.

dotnet/test/webdriver/WebElementTests.cs

WindowSwitchingTests.csUse fixture 'Driver' in window switching tests +128/-128

Use fixture 'Driver' in window switching tests

• Replaces direct driver window handle management with 'Driver' usage throughout switching and cleanup flows.

dotnet/test/webdriver/WindowSwitchingTests.cs

WindowTests.csUse fixture 'Driver' in window tests +35/-35

Use fixture 'Driver' in window tests

• Refactors window operations and assertions to reference 'Driver' consistently.

dotnet/test/webdriver/WindowTests.cs

@qodo-code-review

qodo-code-review Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 15 rules

Grey Divider


Action required

1. EnvironmentManager.Instance still used ✗ Dismissed 📎 Requirement gap ☼ Reliability
Description
Modified test infrastructure code continues to obtain and manage drivers via the global singleton
EnvironmentManager.Instance, preserving shared state and coupling across tests. This violates the
requirement to remove static environment context and can block safe parallel execution due to
cross-test interference.
Code

dotnet/test/webdriver/DriverTestFixture.cs[R57-77]

    [OneTimeSetUp]
    public void SetUp()
    {
-        driver = EnvironmentManager.Instance.GetCurrentDriver();
+        Driver = EnvironmentManager.Instance.GetCurrentDriver();
    }

    [OneTimeTearDown]
    public void TearDown()
    {
        EnvironmentManager.Instance.CloseCurrentDriver();
-        driver?.Dispose();
+        Driver?.Dispose();
    }

    [TearDown]
    public void ResetOnError()
    {
        if (TestContext.CurrentContext.Result.Outcome == Error)
        {
-            driver?.Dispose();
-            driver = EnvironmentManager.Instance.CreateFreshDriver();
+            Driver?.Dispose();
+            Driver = EnvironmentManager.Instance.CreateFreshDriver();
        }
Evidence
PR Compliance ID 389278 requires removing/avoiding static EnvironmentManager-style global context,
and ID 389279 requires parallel-safe infrastructure. The changed code explicitly calls
EnvironmentManager.Instance to get/create/close drivers and assigns the fixture Driver, which
preserves global shared state and increases coupling across tests.

Eliminate static test environment context (remove/avoid static EnvironmentManager usage)
Enable or prepare test infrastructure for effective parallelization
dotnet/test/webdriver/DriverTestFixture.cs[57-77]
dotnet/test/webdriver/Infrastructure/NeedsFreshDriverAttribute.cs[31-48]
dotnet/test/webdriver/DevTools/DevToolsTestFixture.cs[34-57]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The modified test fixtures still depend on `EnvironmentManager.Instance` (a global singleton) to create/get/close WebDriver instances and to mutate the fixture’s `Driver`. This violates the requirement to eliminate static test environment context and undermines parallel-safe execution.

## Issue Context
This PR changes the driver access pattern across the test suite, but it keeps the core lifecycle wired to a shared global `EnvironmentManager.Instance`. To comply, driver/environment management should be instance-scoped (e.g., injected per fixture/test, or provided by NUnit fixtures/DI) rather than static/singleton.

## Fix Focus Areas
- dotnet/test/webdriver/DriverTestFixture.cs[57-77]
- dotnet/test/webdriver/Infrastructure/NeedsFreshDriverAttribute.cs[31-48]
- dotnet/test/webdriver/DevTools/DevToolsTestFixture.cs[34-57]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Driver rename touches many tests 📘 Rule violation ✧ Quality
Description
The driver to Driver fixture change triggers widespread mechanical edits across many test files
and multiple test areas, making the PR large and cross-cutting relative to its stated goal. This
increases review/revert risk and should be split or more narrowly scoped where possible.
Code

dotnet/test/webdriver/DriverTestFixture.cs[R38-46]

    public string formsTitle = "We Leave From Here";

-    public IWebDriver driver { get; set; }
+    protected internal IWebDriver Driver { get; set; }

    public bool IsNativeEventsEnabled
    {
        get
        {
-            if (driver is IHasCapabilities capabilitiesDriver &&
+            if (Driver is IHasCapabilities capabilitiesDriver &&
Evidence
PR Compliance ID 389267 flags large, cross-cutting changes in a single PR. The diff shows a central
fixture API change (driver -> Driver) and corresponding updates across multiple separate test
areas (webdriver tests, support UI tests, remote tests), indicating a broad mechanical refactor
rather than a tightly localized change.

Rule 389267: Avoid large, cross-cutting changes in a single pull request
dotnet/test/webdriver/DriverTestFixture.cs[38-46]
dotnet/test/webdriver/AlertsTests.cs[30-35]
dotnet/test/support/UI/SelectBrowserTests.cs[28-37]
dotnet/test/remote/RemoteWebDriverSpecificTests.cs[54-60]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
This PR introduces a broad, cross-cutting mechanical refactor (changing access/name of the shared driver property) that forces edits across many unrelated test classes.

## Issue Context
Compliance requires avoiding large, cross-cutting PRs unless there is a narrowly-scoped rationale and the change is easily reversible. Consider splitting the core fixture change from the mass call-site updates (or isolating call-site updates into a dedicated mechanical PR/commit).

## Fix Focus Areas
- dotnet/test/webdriver/DriverTestFixture.cs[38-46]
- dotnet/test/webdriver/AlertsTests.cs[30-35]
- dotnet/test/support/UI/SelectBrowserTests.cs[28-37]
- dotnet/test/remote/RemoteWebDriverSpecificTests.cs[54-60]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment thread dotnet/test/webdriver/DriverTestFixture.cs
@nvborisenko nvborisenko merged commit 0113626 into SeleniumHQ:trunk Jun 28, 2026
24 checks passed
@nvborisenko nvborisenko deleted the dotnet-test-driver-protected branch June 28, 2026 15:38
@nvborisenko nvborisenko restored the dotnet-test-driver-protected branch June 28, 2026 15:38
@nvborisenko nvborisenko deleted the dotnet-test-driver-protected branch June 28, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-support Issue or PR related to support classes C-dotnet .NET Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants