PRACTICAL GUIDE / Selenium C# NUnit interview questions

16 Selenium .NET and NUnit Interview Scenarios for Senior SDETs

Practice 16 Selenium .NET and NUnit scenarios on IWebDriver ownership, fixture lifecycle, parallel execution, waits, remote options, evidence, and disposal.

By The Testing AcademyUpdated July 11, 20269 min read
All field guides
In this guide9 sections
  1. Map NUnit to WebDriver Lifetime
  2. NUnit Fixture Scenarios
  3. 1. Why should [SetUp] create a new driver instead of [OneTimeSetUp]?
  4. 2. How would you clean up when setup throws after creating the driver?
  5. 3. Why can parallel NUnit methods corrupt an instance-field driver?
  6. Interface and Page-Layer Scenarios
  7. 4. Why should a page service accept IWebDriver but the factory know concrete driver types?
  8. 5. How would you model a page transition without returning this from every method?
  9. 6. Why should C# page objects avoid public IWebElement properties?
  10. Parallel Ownership Scenarios
  11. 7. How would you allocate one customer record per parallel NUnit case?
  12. 8. Why is ThreadLocal<IWebDriver> not a complete framework architecture?
  13. 9. How would you size parallelism when Grid has fewer usable slots than NUnit workers?
  14. Wait and Assertion Scenarios
  15. 10. Why should WebDriverWait.Until return a typed value when possible?
  16. 11. How would you avoid assertions disappearing inside page methods?
  17. Remote Options Scenarios
  18. 12. Why should a framework prefer browser option classes over a loose capability dictionary?
  19. 13. How would you diagnose requested Chrome but negotiated a different remote environment?
  20. Failure and Disposal Scenarios
  21. 14. Why should screenshot capture be guarded separately from browser-log capture?
  22. 15. How would you decide between Quit and Dispose in an ownership wrapper?
  23. 16. Why is putting Selenium calls inside Task.Run a poor way to speed up one test?
  24. .NET Framework Checklist
  25. Conclusion: Dispose What the Test Owns

What you will learn

  • Map NUnit to WebDriver Lifetime
  • NUnit Fixture Scenarios
  • Interface and Page-Layer Scenarios
  • Parallel Ownership Scenarios

A senior C# Selenium discussion should begin with ownership, not syntax. NUnit may create and schedule fixtures in ways that expose shared fields, while IWebDriver represents a live remote session whose commands mutate one browser. If those lifetimes do not align, polished page objects will still produce cross-test failures.

The scenarios below focus on fixture boundaries, interface design, synchronous binding behavior, remote capability negotiation, and guarded disposal. Each answer should state what the test owns and what evidence remains when that ownership fails.

Map NUnit to WebDriver Lifetime

The official Selenium .NET API defines IWebDriver, browser options, remote sessions, waits, and concrete drivers. Selenium's fresh-browser guidance recommends starting each test from a clean state, with at least a new WebDriver per test when stronger environment isolation is impractical.

Animated field map

.NET Test Session Lifecycle

An NUnit invocation builds browser options, owns one IWebDriver during parallel execution, records outcome evidence, and disposes it safely.

  1. 01 / nunit fixture

    NUnit fixture

    Establish one test invocation and its setup dependencies.

  2. 02 / browser options

    Browser options

    Translate validated settings into standard capabilities.

  3. 03 / webdriver instance

    IWebDriver instance

    Open one local or remote session for the invocation.

  4. 04 / parallel execution

    Parallel test execution

    Keep browser, page objects, and mutable data with one owner.

  5. 05 / guarded disposal

    Guarded disposal

    Capture failure evidence and release the exact owned session.

The design target is not one driver factory call. It is a complete path in which setup failure, assertion failure, and teardown failure remain distinguishable.

NUnit Fixture Scenarios

1. Why should [SetUp] create a new driver instead of [OneTimeSetUp]?

[SetUp] runs for each test case, so the browser's cookies, windows, profile, and navigation begin from a known session boundary. A one-time driver makes methods order-dependent and lets one crash poison the rest of the fixture. I would reserve [OneTimeSetUp] for immutable configuration or an external client designed for sharing, never a mutable UI session.

2. How would you clean up when setup throws after creating the driver?

Track construction in a local variable and transfer it to the test context only after all mandatory setup succeeds. A catch block disposes the partial session and rethrows the original exception. [TearDown] must also tolerate the absence of a driver. Otherwise a null dereference or disposal failure can replace the useful new-session or navigation error.

3. Why can parallel NUnit methods corrupt an instance-field driver?

The fixture object can expose the same field to concurrently scheduled methods, depending on the configured fixture lifecycle. Each setup assignment races with commands and teardown from another method. I would use an instance-per-test-case lifecycle where deliberately configured or resolve an invocation-scoped browser fixture. The design must be correct under the runner settings actually used in CI, not assumptions from serial execution.

Interface and Page-Layer Scenarios

4. Why should a page service accept IWebDriver but the factory know concrete driver types?

The page needs standard navigation, element lookup, window, and script capabilities represented by the interface. The factory must construct ChromeDriver, FirefoxDriver, or RemoteWebDriver and may configure a local service. Keeping that concrete choice at the boundary prevents tests from casting casually. A browser-specific feature deserves a separate capability interface or adapter with explicit support checks.

5. How would you model a page transition without returning this from every method?

Return the page or domain result that exists after the operation. Login can return a dashboard on success, while a rejected login may return a typed validation result from a different method. Unconditional fluent this chains hide navigation and allow commands against an obsolete page. Constructors can verify a cheap loaded invariant, and transitions should wait for the destination evidence they promise.

6. Why should C# page objects avoid public IWebElement properties?

Public elements expose selectors and remote references to tests, encourage assertions at the wrong level, and can become stale across renders. Keep locators private and expose behavior or immutable values. A component object may hold a root element only for a tightly bounded DOM lifetime; after replacement, the containing page should locate a new component instead of retrying arbitrary operations on stale references.

Parallel Ownership Scenarios

7. How would you allocate one customer record per parallel NUnit case?

Create or lease the record in per-test setup using a run id plus NUnit test id, then pass a typed customer handle to the scenario. The allocator must coordinate through the backend or another atomic store; a static C# counter protects only one process. Cleanup uses the exact id and is idempotent. Reports include a safe alias so collisions can be traced without exposing credentials.

8. Why is ThreadLocal<IWebDriver> not a complete framework architecture?

It maps a value to a thread, but tests can use asynchronous setup, runner scheduling can evolve, and other mutable state may remain static. It also requires explicit disposal and removal. I prefer a test-context resource passed into page services. If ThreadLocal is retained for legacy access, wrap it, fail on missing ownership, and clear it immediately after disposing the driver.

9. How would you size parallelism when Grid has fewer usable slots than NUnit workers?

Match concurrency to the capability-specific capacity, not the Grid's total node count. If workers exceed compatible slots, session creation queues and fixture timeouts can masquerade as application slowness. Set a bounded session-start timeout, expose queue evidence, and separate browser matrices into capacity-aware lanes. Increasing NUnit's parallel level is not useful when downstream ownership cannot be granted.

Wait and Assertion Scenarios

10. Why should WebDriverWait.Until return a typed value when possible?

The delegate can return the element or domain evidence that satisfied the condition, avoiding a second remote read after readiness. For example, return an immutable OrderSummary only when status and total agree. The condition should treat expected transitional states as incomplete and let invalid selectors or disconnected sessions escape. Catching all WebDriverException converts protocol failures into misleading timeouts.

CSHARP
OrderSummary summary = wait.Until(d =>
{
    var value = ReadOrderSummary(d);
    return value.Status == "Confirmed" ? value : null;
});
Assert.That(summary.Total, Is.EqualTo(expectedTotal));

11. How would you avoid assertions disappearing inside page methods?

Page methods return observable values or domain results; NUnit assertions stay in the scenario or a focused domain assertion object. A page constructor may reject an obviously wrong page because that is its invariant. This split makes reports say "confirmed total was wrong" instead of "checkout helper failed" and allows the same interaction to support several legitimate outcomes.

Remote Options Scenarios

12. Why should a framework prefer browser option classes over a loose capability dictionary?

ChromeOptions, FirefoxOptions, and other binding types encode supported standard and browser-specific settings and participate in W3C new-session negotiation. A loose dictionary makes misspelled names and incompatible values easy. I would validate common settings into a target record, build the right options, and isolate any remote provider's namespaced capabilities in one adapter.

13. How would you diagnose requested Chrome but negotiated a different remote environment?

Record sanitized requested capabilities and driver.Capabilities after session creation. Compare browser name, platform, and relevant options with the intended target. The remote distributor may have matched a broader request than expected. If an attribute is mandatory, express it as a valid capability and fail setup when the negotiated session violates the framework contract rather than allowing scenario failures later.

Failure and Disposal Scenarios

14. Why should screenshot capture be guarded separately from browser-log capture?

A closed window can break screenshots while logs or session capabilities remain available; an unsupported log type can fail while the page is still capturable. Run each evidence operation independently and attach its own diagnostic on failure. Then release the driver in finally. One broad artifact block makes the least reliable evidence source capable of suppressing everything else.

15. How would you decide between Quit and Dispose in an ownership wrapper?

Expose one idempotent release operation on the wrapper and follow the binding's disposal contract, ensuring session deletion occurs once. Callers should not scatter both methods or dispose a driver they did not create. The wrapper records whether construction completed and guards repeated cleanup. Finalizers are not a timely test cleanup mechanism; NUnit teardown must release the remote session deterministically.

16. Why is putting Selenium calls inside Task.Run a poor way to speed up one test?

The binding's commands target one stateful session, and concurrent navigation or element operations have dependent browser semantics. Task.Run merely moves synchronous work to pool threads; it does not create independent protocol sessions or make the driver safe for concurrent use. Speed comes from running isolated tests in parallel, reducing unnecessary UI setup, and using APIs for non-UI preconditions.

.NET Framework Checklist

  • Align NUnit fixture lifetime with one owned browser per test invocation.
  • Keep concrete driver construction and provider capabilities in infrastructure.
  • Pass interfaces and typed domain evidence to page and assertion layers.
  • Coordinate mutable test data outside process-local static collections.
  • Distinguish explicit-wait timeout, remote-command failure, and setup failure.
  • Capture each artifact independently before deterministic disposal.
  • Validate requested and negotiated capabilities for remote sessions.

Conclusion: Dispose What the Test Owns

The reliable .NET design is straightforward to state and demanding to enforce: one NUnit invocation owns one configured IWebDriver, every page service stays within that lifetime, and teardown preserves evidence before releasing it. Parallelism then becomes a scheduling decision over isolated units, not a gamble over shared fields. That is the standard a senior SDET should defend.

// LIVE COURSE / THE TESTING ACADEMY

Playwright Automation Mastery

Go beyond Selenium. Master Playwright with JS/TS in 90 days.

From the instructor behind this guide.

Playwright jobs are growing 8x faster than Selenium. 90 days / 75+ live hrs / Tue-Thu-Sat 7 AM IST.

Code PROMODE / 10% offJoin the batch

The Testing Academy editorial desk

Practical QA guidance built around test evidence, production tradeoffs, and interview-ready explanations.

Published July 11, 2026 / Reviewed July 11, 2026

PRIMARY REFERENCES

Verify the details at the source

QABattle guides are practical explanations. Product behavior, standards, and APIs can change, so use these primary references for the canonical details.

  1. 01
    Selenium documentation

    Selenium Project

    Canonical WebDriver, Grid, waits, element, and browser automation guidance.

  2. 02
    WebDriver standard

    W3C

    The browser automation protocol specification behind WebDriver implementations.

FAQ / QUICK ANSWERS

Questions testers ask

Should an NUnit fixture keep IWebDriver in an instance field?

Only when the fixture lifecycle guarantees that the field belongs to one test at a time. With parallel test methods, prefer per-test ownership stored in an invocation-safe context or passed through a fixture object.

When should C# tests depend on IWebDriver instead of ChromeDriver?

Tests and page services should usually accept IWebDriver because they need standard browser operations. Infrastructure may retain a concrete driver or capability interface for a deliberate browser-specific feature.

Is OneTimeSetUp a good place to create a shared browser?

Usually not. A shared browser leaks cookies, windows, navigation, and failures across tests and conflicts with parallel execution. Use OneTimeSetUp for immutable suite resources, not mutable WebDriver sessions.

How should teardown preserve an NUnit assertion failure?

Capture browser evidence with individually guarded operations, then dispose the owned driver in finally. Report capture or disposal problems as teardown diagnostics without replacing the original assertion and stack trace.

Can Task.Run make synchronous Selenium commands safely parallel?

No. Wrapping calls in Task.Run does not make one IWebDriver thread-safe or give commands independent browser state. Parallelize isolated test cases, each with its own session and data.