Atata.WebDriverSetup is a .NET library that sets up browser drivers for Selenium WebDriver,
e.g. chromedriver
, geckodriver
, etc.
Basically, it provides functionality similar to Java WebDriverManager
.
The package targets .NET Standard 2.0, which supports .NET 5+, .NET Framework 4.6.1+ and .NET Core/Standard 2.0+.
- Features
- Installation
- Usage
- DriverSetup Members
- Configuration
- BrowserDetector
- Feedback
- SemVer
- License
- Sets up drivers for browsers: Chrome, Firefox, Edge, Internet Explorer and Opera.
- Supports Windows, Linux and macOS platforms.
- Can download latest or specific driver versions.
- Can auto-detect locally installed browser version and download corresponding driver version.
- Caches the used driver versions.
- After a driver is set up, adds the driver path to environment "PATH" variable, which is consumed by WebDriver.
Install Atata.WebDriverSetup
NuGet package.
-
Package Manager:
Install-Package Atata.WebDriverSetup
-
.NET CLI:
dotnet add package Atata.WebDriverSetup
The package depends on:
Microsoft.Win32.Registry
- is used to detect locally installed browser version through Windows Registry.Atata.Cli
- is used to detect locally installed browser version through CLI on Linux and macOS.System.Text.Json
- is used to read JSON HTTP responses.
The main class is DriverSetup
.
The recommended place to perform driver(s) setup is a global set up method.
NUnit example:
[SetUpFixture]
public class SetUpFixture
{
[OneTimeSetUp]
public void SetUp()
{
DriverSetup.AutoSetUp(BrowserNames.Chrome);
}
}
After a driver is set up, the driver path is added to environment "PATH" variable, which is read by WebDriver's DriverService classes.
ChromeDriver chromeDriver = new ChromeDriver();
- Configure with default configuration options:
DriverSetup.AutoSetUp(BrowserNames.Chrome);
- Configure with custom configuration options:
DriverSetup.ConfigureChrome() .WithAutoVersion() // Additional options can be set here. .SetUp();
DriverSetup.AutoSetUp
method also supports multiple drivers setup:
DriverSetup.AutoSetUp(BrowserNames.Chrome, BrowserNames.Edge);
Note: If the version of browser cannot be detected automatically, latest driver version is used. Version auto-detection is currently supported for Chrome, Firefox and Edge browsers.
DriverSetup.ConfigureChrome()
.WithLatestVersion()
.SetUp();
DriverSetup.ConfigureChrome()
.WithVersion("87.0.4280.88")
.SetUp();
Version format:
- Chrome:
"87.0.4280.88"
- Firefox:
"0.28.0"
- Edge:
"89.0.774.4"
- Opera:
"86.0.4240.80"
- InternetExplorer:
"3.141.59"
DriverSetup.ConfigureChrome()
.ByBrowserVersion("87")
.SetUp();
Note: This feature is currently supported for Chrome, Firefox and Edge browsers.
Version format:
- Chrome:
"87"
or"87.0.4280"
- Firefox:
"104"
,"104.0"
or"104.0.1"
- Edge:
"89.0.774.4"
DriverSetup
is a static class, so all its members are static too.
DriverSetupOptions GlobalOptions { get; }
Gets the global setup options.DriverSetupOptionsBuilder GlobalConfiguration { get; }
Gets the global setup configuration builder. ConfiguresGlobalOptions
.List<DriverSetupConfigurationBuilder> PendingConfigurations { get; }
Gets the pending driver setup configurations, the configurations that were created but were not set up.
DriverSetupConfigurationBuilder ConfigureChrome()
Creates the Chrome driver setup configuration builder.DriverSetupConfigurationBuilder ConfigureFirefox()
Creates the Firefox/Gecko driver setup configuration builder.DriverSetupConfigurationBuilder ConfigureEdge()
Creates the Edge driver setup configuration builder.DriverSetupConfigurationBuilder ConfigureOpera()
Creates the Opera driver setup configuration builder.DriverSetupConfigurationBuilder ConfigureInternetExplorer()
Creates the Internet Explorer driver setup configuration builder.DriverSetupConfigurationBuilder Configure(string browserName)
Creates the driver setup configuration builder for the specifiedbrowserName
. Supported browser names are defined inBrowserNames
static class.DriverSetupConfigurationBuilder Configure(string browserName, Func<IHttpRequestExecutor, IDriverSetupStrategy> driverSetupStrategyFactory)
Creates the driver setup configuration builder usingdriverSetupStrategyFactory
that instantiates specificIDriverSetupStrategy
.DriverSetupResult AutoSetUp(string browserName)
&
Task<DriverSetupResult> AutoSetUpAsync(string browserName)
Sets up driver with auto version detection for the browser with the specified name. Supported browser names are defined inBrowserNames
static class.DriverSetupResult[] AutoSetUp(params string[] browserNames)
&
DriverSetupResult[] AutoSetUp(IEnumerable<string> browserNames)
&
Task<DriverSetupResult[]> AutoSetUpAsync(params string[] browserNames)
&
Task<DriverSetupResult[]> AutoSetUpAsync(IEnumerable<string> browserNames)
Sets up drivers with auto version detection for the browsers with the specified names. Supported browser names are defined inBrowserNames
static class.DriverSetupResult[] AutoSetUpSafely(IEnumerable<string> browserNames)
&
Task<DriverSetupResult[]> AutoSetUpSafelyAsync(IEnumerable<string> browserNames)
Sets up drivers with auto version detection for the browsers with the specified names. Supported browser names are defined inBrowserNames
static class. Skips invalid/unsupported browser names.DriverSetupOptionsBuilder GetDefaultConfiguration(string browserName)
Gets the default driver setup configuration builder.DriverSetupResult[] SetUpPendingConfigurations()
&
Task<DriverSetupResult[]> SetUpPendingConfigurationsAsync()
Sets up pending configurations that are stored inPendingConfigurations
property.void RegisterStrategyFactory(string browserName, Func<IHttpRequestExecutor, IDriverSetupStrategy> driverSetupStrategyFactory)
Registers the driver setup strategy factory.
It's possible to set configuration options globally and separately for a specific driver.
DriverSetup.GlobalConfiguration
.WithStorageDirectoryPath("...")
.WithVersionCache(false);
DriverSetup.GlobalOptions.StorageDirectoryPath = "...";
DriverSetup.GlobalOptions.UseVersionCache = false;
DriverSetup.GetDefaultConfiguration(BrowserNames.InternetExplorer)
.WithX32Architecture();
DriverSetup.ConfigureChrome()
.WithStorageDirectoryPath("...")
.WithVersionCache(false)
.SetUp();
Don't forget to call SetUp()
or SetUpAsync()
at the end.
WithAutoVersion()
Sets the automatic driver version detection by installed browser version. If the version cannot be detected automatically, latest driver version should be used.WithLatestVersion()
Sets the latest version of driver.ByBrowserVersion(string version)
Sets the browser version. It will find driver version corresponding to the browser version.WithVersion(string version)
Sets the version of driver to use.WithEnvironmentVariableName(string variableName)
Sets the name of the environment variable that will be set with a value equal to the driver directory path. The default value is specific to the driver being configured. It has"{BrowserName}Driver"
format. For example:"ChromeDriver"
or"InternetExplorerDriver"
. Thenull
value means that none variable should be set.
WithStorageDirectoryPath(string path)
Sets the storage directory path. The default value is"{basedir}/drivers")
.WithX32Architecture()
Sets the x32 (x86) architecture.WithX64Architecture()
Sets the x64 architecture.WithArm64Architecture()
Sets the ARM64 architecture.WithArchitecture(Architecture architecture)
Sets the architecture. The default value isArchitecture.Auto
.WithProxy(IWebProxy proxy)
Sets the web proxy.WithCheckCertificateRevocationList(bool checkCertificateRevocationList)
Sets a value indicating whether the certificate is automatically picked from the certificate store or if the caller is allowed to pass in a specific client certificate. The default value istrue
.WithHttpClientHandlerConfiguration(Action<HttpClientHandler> httpClientHandlerConfigurationAction)
Sets the configuration action ofHttpClientHandler
. TheHttpClientHandler
instance is used to get a driver version information and to download a driver archive.WithMutex(bool isEnabled)
Sets a value indicating whether to use mutex to sync driver setup across machine.. The default value istrue
.WithVersionCache(bool isEnabled)
Sets a value indicating whether to use version cache. The default value istrue
.WithLatestVersionCheckInterval(TimeSpan interval)
Sets the latest version check interval. The default values is2
hours.WithSpecificVersionCheckInterval(TimeSpan interval)
Sets the specific version check interval. The default values is2
hours.WithHttpRequestTryCount(int count)
Sets the HTTP request try count. The default values is3
.WithHttpRequestRetryInterval(TimeSpan interval)
Sets the HTTP request retry interval. The default values is3
seconds.WithEnabledState(bool isEnabled)
Sets a value indicating whether the configuration is enabled. The default values istrue
.WithAddToEnvironmentPathVariable(bool isEnabled)
Sets a value indicating whether to add the driver directory path to environment "Path" variable. The default value istrue
.
Rarely you can get HTTP certificate errors during driver setup. In order to handle such errors you can try one or both of the configuration settings below.
DriverSetup.GlobalConfiguration
.WithCheckCertificateRevocationList(false)
.WithHttpClientHandlerConfiguration(x => x.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator);
BrowserDetector
- provides a set of static methods for a detection of browser installations.
Browser detection is supported for Chrome, Firefox and Edge,
so as a browser name the following constants can be used:
BrowserNames.Chrome
BrowserNames.Firefox
BrowserNames.Edge
string GetInstalledBrowserVersion(string browserName)
Gets the installed browser version by the browser name.bool IsBrowserInstalled(string browserName)
Determines whether the browser with the specified name is installed.string GetFirstInstalledBrowserName(params string[] browserNames)
Gets the name of the first installed browser among thebrowserNames
.string GetFirstInstalledBrowserName(IEnumerable<string> browserNames)
Gets the name of the first installed browser among thebrowserNames
.
string browserName = BrowserDetector.GetFirstInstalledBrowserName(
BrowserNames.Chrome,
BrowserNames.Firefox,
BrowserNames.Edge);
bool isChromeInstalled = BrowserDetector.IsBrowserInstalled(BrowserNames.Chrome);
string chromeVersion = BrowserDetector.GetInstalledBrowserVersion(BrowserNames.Chrome);
Any feedback, issues and feature requests are welcome.
If you faced an issue please report it to Atata.WebDriverSetup Issues, ask a question on Stack Overflow using atata tag or use another Atata Contact way.
Atata Framework follows Semantic Versioning 2.0. Thus backward compatibility is followed and updates within the same major version (e.g. from 1.3 to 1.4) should not require code changes.
Atata is an open source software, licensed under the Apache License 2.0. See LICENSE for details.