Skip to content

Latest commit

 

History

History
120 lines (82 loc) · 7.57 KB

AGENTS.md

File metadata and controls

120 lines (82 loc) · 7.57 KB

AGENTS.md

This file provides guidance to coding agents working in this repository.

Project Overview

A C# library that implements Selenium's IWebDriver interface using Playwright as the underlying browser automation engine. This enables existing Selenium test suites to use Playwright as a drop-in replacement without rewriting tests.

Two NuGet packages are published:

  • TomLonghurst.Selenium.PlaywrightWebDriver — Selenium v4
  • TomLonghurst.Selenium.V3.PlaywrightWebDriver — Selenium v3

The library targets netstandard2.0. Dual Selenium version support is achieved via conditional compilation: SeleniumVersion_3 and SeleniumVersion_4 (default) constants, controlled by the SeleniumVersion MSBuild property.

Build & Test Commands

# Build the solution
dotnet build

# Run tests (NUnit, requires Playwright browsers installed)
dotnet test

# Run a single test by name
dotnet test --filter "FullyQualifiedName~TestMethodName"

# Run the full CI pipeline (build + test + pack)
dotnet run -c Release --framework net8.0 --project TomLonghurst.Selenium.PlaywrightWebDriver.Pipeline

# Build for Selenium v3
dotnet build -p:SeleniumVersion=3

Tests require Playwright browser binaries. The test project's GlobalSetUp.cs runs pwsh playwright.ps1 install automatically via [OneTimeSetUp].

Architecture

Adapter Pattern (Selenium → Playwright)

The core design maps Selenium's synchronous IWebDriver contract onto Playwright's async APIs:

Selenium Interface Playwright Adapter Purpose
IWebDriver PlaywrightWebDriver Main driver, page navigation, element finding
IWebElement PlaywrightWebElement Element interactions (click, text, attributes)
ITargetLocator PlaywrightTargetLocator Switching frames, windows, alerts
INavigation PlaywrightNavigation Back, forward, goto, refresh
IOptions PlaywrightOptions Facade returning timeouts, cookies, window, logs
ICookieJar PlaywrightCookieJar Cookie CRUD operations
IWindow PlaywrightWindow Window size/position
IAlert PlaywrightAlert Alert handling (auto-dismiss, text retrieval only)
IJavaScriptExecutor PlaywrightWebDriver Script execution with argument conversion

Sync-over-Async

Playwright is fully async; Selenium's IWebDriver is sync. The bridge uses TaskExtensions.Synchronously() (wraps GetAwaiter().GetResult()). This is a known architectural constraint.

Locator Conversion

LocatorHelpers converts Selenium By locators to Playwright selectors:

  • By.Id("x") → #x
  • By.ClassName("x") → .x
  • By.CssSelector(...) → css=...
  • By.XPath(...) → xpath=...
  • By.LinkText(...) → a:text-is(...)
  • By.PartialLinkText(...) → a:has-text(...)
  • PlaywrightBy.Selector(...) — pass native Playwright selectors through Selenium APIs

Page/Window Management

PlaywrightWebDriver tracks multiple pages via KeyToPage dictionary (GUID string → IPage). Frame navigation uses CurrentFrameLocators HashSet for nested frame support. The CurrentPage setter automatically clears frame context and brings the page to front.

Script Execution

ExecuteScript/ExecuteAsyncScript convert Selenium script conventions to Playwright:

  • Wraps arguments[n] references into Playwright's function parameter style
  • Converts PlaywrightWebElement args to ElementHandle for Playwright evaluation
  • Strips return statements where Playwright expects expression evaluation

Known Limitations (by design)

  • Manage().Logs — stub, not implemented
  • Manage().Network — stub, not implemented (Selenium v4 only)
  • Alerts auto-dismiss; Accept()/Dismiss() are no-ops; SendKeys() unsupported
  • ExecuteScript parameter/return value behavior may differ from Selenium

Project Structure

  • TomLonghurst.Selenium.PlaywrightWebDriver/ — Main library (netstandard2.0)
  • TomLonghurst.Selenium.PlaywrightWebDriver.Tests/ — NUnit integration tests (net6.0), HTML fixtures in HtmlPages/
  • TomLonghurst.Selenium.PlaywrightWebDriver.Pipeline/ — ModularPipelines-based CI/CD (build, test, pack, publish to NuGet)

CI/CD

GitHub Actions workflow (.github/workflows/dotnet.yml) runs the Pipeline project. Publishing to NuGet requires manual workflow_dispatch with publish-packages: true on the main branch. The NuGet__ApiKey secret is only available in the Production environment.

Pull request reviews

  • Resolve each PR review thread, whether a human or a bot opened it, as soon as you have dispositioned it: the fix is pushed to the PR head and your reply names the commit, or your reply pushes back on the finding with evidence. Leave a thread open only while it has no disposition. If the reviewer replies after your disposition, unresolve the thread and handle the reply.

Autonomous self-improvement

Treat every problem you notice as work to act on, whether you find it while testing, developing, reading code, reviewing, or doing anything else. Examples include bugs, flaky or failing tests, incorrect docs, misleading comments, broken tooling, and gaps in these instructions.

  • If the fix is trivial and low-risk, fix it as part of the current work and mention it in the PR description.
  • If the fix is out of scope for the current work, raise a GitHub issue at the point you discover it so it can be fixed later. Include what you saw, where you saw it (file and line, command, or CI run), how to reproduce it, and the expected behavior. Search existing issues first, and add to a matching issue instead of opening a duplicate. Write it as Writing issues describes.
  • Do not ignore a problem because it existed before your change or is unrelated to it.

Writing issues

Every issue must be understood by a reader who has never seen Selenium.PlaywrightDriver, from its title and first paragraph alone. This matters most in another project's repository: its maintainers do not know our code, terms or constraints, and an issue they cannot follow gets ignored or closed.

  • Title: the observed problem or the requested capability in that project's own API terms, for example "BasicPublishAsync rejects ReadOnlyMemory<byte> header values". No Selenium.PlaywrightDriver names or shorthand.
  • Summary first: open with two or three plain sentences: what happens, what you expected, and why a user of that project would care. Details come after.
  • Their vocabulary, not ours: do not use Selenium.PlaywrightDriver's internal type, component or decision names, or our own targets and budgets; say what the code does instead. Use the project's issue template when it has one.
  • Short sections: Summary, Reproduction, Expected and actual, Environment (exact versions); for a feature, Proposal instead of Expected and actual. The reproduction is minimal and self-contained, never needs Selenium.PlaywrightDriver, and source links are pinned to the tag you checked.
  • One ask, stated once: one problem per issue. End with a direct question or request, not a menu of options.
  • Cut what the maintainer does not need to act: investigation narrative, hedging, our workarounds, local paths, worktree names, internal CI details. Mention Selenium.PlaywrightDriver once, at the end, with a link to the tracking issue.
  • Check before filing: search the project's open and closed issues, and its main branch and unreleased release notes, not only the version we use.
  • Reread as the maintainer: could they tell within 30 seconds what is wrong and what you are asking? If a maintainer says an issue is unclear, rewrite the body in place, then reply with a short plain summary.