A library to ease the configuration and launch of Selenium WebDriver instances in .net projects. Supports browser instances run locally or on a Selenium 4.x grid. Supported Browsers: Chrome Firefox Microsoft Edge Internet Explorer 11 (Windows Platforms) Safari (MacOS) Platforms: Windows (PlatformType.Windows) Linux (PlatformType.Linux) MacOS (PlatformType.Mac) Tested and working on Windows 10, Windows 11, Linux (Ubuntu 20.04.3 LTS) and macOS Monterey The repository at https://github.com/AlexanderOnTest/NetCoreWebDriverFactory contains test projects for Windows, Linux and MacOS. These can be used to test your setup and demonstrate the options available. The supporting package https://www.nuget.org/packages/Selenium.WebDriver.WebDriverFactoryNunitConfig provides easy test configuration options if using Nunit 3 for your tests.
$ dotnet add package Selenium.WebDriver.NetCoreWebDriverFactoryAn extensible library to ease the configuration and launching of Selenium WebDriver instances in .net / .net Core / .net Framework projects. Supports browser instances run locally or on a Selenium grid v4.
Supported Browsers:
Platforms:
Tested and working on Windows 10/11, Linux (Ubuntu 22.04) and macOS Monterey
Selenium.WebDriver.WebDriverFactoryNunitConfig provides additional code to pull the required configuration from *.runsettings files including the option to override with local configuration files.
This can be used to completely separate WebDriver configuration from your test code.
ServiceCollectionFactory.cs includes static methods that provide a configured Microsoft.Extensions.DependencyInjection.IServiceCollection for use in your project although you may prefer to use the code as inspiration for your own implementation / module.
e.g. NUnit3 example
private IWebDriverFactory webDriverFactory;
[OneTimeSetUp]
public void Setup()
{
IServiceCollection serviceCollection = ServiceCollectionFactory.GetDefaultServiceCollection();
IServiceProvider provider = serviceCollection.BuildServiceProvider();
webDriverFactory = provider.GetRequiredService<IWebDriverFactory>();
}
WebDriverConfigurationBuilder.cs provides a fluent interface to generate an IWebDriverConfiguration.cs defining the characteristics of the WebDriver instance you desire.
e.g.
IWebDriverConfiguration configuration = WebDriverConfigurationBuilder.Start()
.WithBrowser(Browser.Firefox)
.RunHeadless()
.RunRemotelyOn(new Uri("http://localhost:4444"))
.WithPlatformType(PlatformType.Mac)
.WithLanguageCulture(new CultureInfo("es-Es"))
.WithWindowSize(WindowSize.Fhd)
.Build();
IWebDriver driver = webDriverFactory.GetWebDriver(configuration);
To generate and reuse one or more WebDriver instances of a single configuration use a WebDriverManager.cs
IWebDriverManager webDriverManager = new WebDriverManager(webDriverFactory, configuration)
IWebDriver driver = webDriverManager.Get();
Repeated calls to webDriverManager.Get() will return the same singleton IWebDriver instance until it is closed by calling webDriverManager.Quit().
The library attempts to provide informative exceptions where the requested WebDriver does not support the requested options. As supported features do change, these are not guaranteed to remain correct.
All services are defined as interfaces so you can provide alternative or additional implementations if needed.