TomLonghurst.Selenium.V3.PlaywrightWebDriver 1.0.42

Prefix Reserved
dotnet add package TomLonghurst.Selenium.V3.PlaywrightWebDriver --version 1.0.42                
NuGet\Install-Package TomLonghurst.Selenium.V3.PlaywrightWebDriver -Version 1.0.42                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TomLonghurst.Selenium.V3.PlaywrightWebDriver" Version="1.0.42" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TomLonghurst.Selenium.V3.PlaywrightWebDriver --version 1.0.42                
#r "nuget: TomLonghurst.Selenium.V3.PlaywrightWebDriver, 1.0.42"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TomLonghurst.Selenium.V3.PlaywrightWebDriver as a Cake Addin
#addin nuget:?package=TomLonghurst.Selenium.V3.PlaywrightWebDriver&version=1.0.42

// Install TomLonghurst.Selenium.V3.PlaywrightWebDriver as a Cake Tool
#tool nuget:?package=TomLonghurst.Selenium.V3.PlaywrightWebDriver&version=1.0.42                

Selenium.PlaywrightDriver

Use Playwright as if it was a Selenium WebDriver

Installation/Usage

If you're using Selenium v4

  • Install package TomLonghurst.Selenium.PlaywrightWebDriver

If you're using Selenium v3

  • Install package TomLonghurst.Selenium.V3.PlaywrightWebDriver

As per the playwright instructions, you need to run the playwright install script to install browser binaries and such:

pwsh bin/Debug/netX/playwright.ps1 install

This can be achieved in C# by something similar to:

Process.Start(new ProcessStartInfo("pwsh")
{
    Arguments = "playwright.ps1 install",
    WorkingDirectory = Environment.CurrentDirectory
})!.WaitForExit();

Anywhere you are using concrete types (e.g. ChromeWebDriver), change them to the IWebDriver interface

Then just create a PlaywrightWebDriver and use that!

await using var driver = await PlaywrightWebDriver.CreateAsync();

driver.Url = "https://www.tomlonghurst.com";

driver.FindElement(By.ClassName("logo__img")).Click();

The static Create/CreateAsync methods can take the Playwright BrowserTypeLaunchOptions and BrowserNewContextOptions if you want to customise things like browser type, proxys, mobile emulation, etc.

Your PlaywrightWebDriver will also expose the underlying instances of IPlaywright, IBrowser and IBrowserContext if you need to use/manipulate those objects for any specific reason.

Motivation

I've come across lots of code bases where there are old, large test suites written in Selenium. These are important for confirming the health of a system, so we can't just delete them. But it'd also be a lot of work to migrate/convert them all.

Selenium supports different WebDrivers through the IWebDriver contract interface. So I thought, is it possible for me to map the Playwright APIs to the Selenium APIs? If we adhere to that interface, we could just drop in a Playwright driver, and we're not actually using the Selenium tech stack anymore.

What's wrong with Selenium anyway? If you're not experiencing any problems, then great. But here's some things I've experienced:

  • It's not asynchronous - So extra pressure on the thread pool. (I know this package isn't either, due to the IWebDriver interface, but if this does help you migrate, then you'll be in an async Playwright world!)
  • It's slow
  • Spawning new browser instances just randomly crashes sometimes with unknown errors, or port problems, or connectivity problems
  • Waiting for elements/pages is flaky
  • Just random "UNKNOWN_ERROR" exceptions!?

Caveats

  • The parameters, arguments and objects returned by ExecuteScript may be different, and so your code surrounding scripts may need to be tweaked
  • Alerts auto dismiss. So Alert.Accept() or Alert.Dismiss() don't actually do anything. Alert.SendKeys(text) is not supported.
  • The WebDriver.Manage().Network functionality has not been implemented
  • The WebDriver.Manage().Logs functionality has not been implemented
  • Sync-over-async. Playwright is async, but Selenium is not. So this was necessary to adhere to the IWebDriver interface. This means that this may be slower than a pure playwright solution due to more pressure on the thread pool. There's also always the risk of sync-over-async deadlocks. As such, this package is recommended as a migration strategy, and you should migrate to the pure playwright API if/when possible.

Bonus

You can start using Playwright selectors even with the Selenium APIs. Instead of using the By.Id(...) class, you can use the PlaywrightBy.Selector(...) class. You can pass this in anywhere you'd pass in a normal By object!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.42 84 10/29/2024
1.0.4 188 4/13/2024
1.0.0 100 4/12/2024
0.1.24 109 4/11/2024
0.1.23 113 4/11/2024
0.1.21 116 4/11/2024
0.1.19 103 4/11/2024
0.1.17 110 4/11/2024
0.1.16 106 4/11/2024
0.1.15 105 4/11/2024
0.1.13 126 4/11/2024
0.1.12 105 4/11/2024