Class WebDriverCreationOptions
- Namespace
- CSF.Extensions.WebDriver.Factories
- Assembly
- CSF.Extensions.WebDriver.dll
Describes the implementation and options for the creation of a web driver.
public class WebDriverCreationOptions
- Inheritance
-
WebDriverCreationOptions
- Inherited Members
Remarks
For most local WebDriver scenarios, the only mandatory properties for this object are DriverType and OptionsFactory. For remote WebDrivers, the OptionsType property is mandatory and the GridUrl property is recommended.
Properties
AddBrowserIdentification
Gets a value which indicates whether or not the created WebDriver should be enriched with browser identification functionality.
public bool AddBrowserIdentification { get; set; }
Property Value
Remarks
If this property is set to true (which is the default if left unset) then the implementation of OpenQA.Selenium.IWebDriver returned by a factory which uses this object as a parameter will be enriched and will implement IHasBrowserId in addition to its usual interfaces.
This functionality, if enabled, will mean that the WebDriver returned by the factory will be a proxy object and not the original WebDriver implementation. For more information on proxies created by this library and their implications, see IGetsProxyWebDriver.
AddBrowserQuirks
Gets a value which indicates whether or not the created WebDriver should be enriched with browser quirks functionality.
public bool AddBrowserQuirks { get; set; }
Property Value
Remarks
For more information about this functionality, please see the documentation for IHasQuirks
This functionality, if enabled, will mean that the WebDriver returned by the factory will be a proxy object and not the original WebDriver implementation. For more information on proxies created by this library and their implications, see IGetsProxyWebDriver.
If this property is true then the value of AddBrowserIdentification is irrelevant; browser identification will always be added to the proxy when quirks are added.
DriverFactoryType
Unneeded except in unusual circumstances, gets or sets the name of a type which is used to construct the WebDriver instance.
public string DriverFactoryType { get; set; }
Property Value
Remarks
This property is unneeded and should be set to null in almost all circumstances.
For all WebDriver implementations bundled with Selenium and most expected third party implementations, this library can
automatically instantiate them without additional logic.
This library can correctly instantiate all WebDrivers that are included with the Selenium.WebDriver
NuGet package.
This library can also automatically instantiate any third-party WebDriver implementation so long as it has a public
constructor which takes a single parameter, which is of a type that derives from OpenQA.Selenium.DriverOptions.
If DriverType is set to a third-party WebDriver implementation which does not follow the pattern above, such as one which has a different constructor parameter signature, this library requires some help in instantiating the WebDriver. In that case (only), this property should be set to the assembly-qualified type name of a type which implements ICreatesWebDriverFromOptions. That type must be provided by the developer using this library. The factory is responsible for constructing the WebDriver instance from options and returning it.
When using a factory of this kind, the factory class which implements ICreatesWebDriverFromOptions must either:
- Be available through dependency injection; add it to your service collection
- Have a public parameterless constructor, such that it may be created via CreateInstance(Type)
- See Also
DriverType
Gets or sets a value indicating the concrete Type name of the class which should be used as the OpenQA.Selenium.IWebDriver implementation.
public string DriverType { get; set; }
Property Value
Examples
To use the Google Chrome implementation of OpenQA.Selenium.IWebDriver, shipped with Selenium, this property should be
set to the value ChromeDriver
.
To use a (fictitious) WebDriver named ElephantDriver, from an assembly named PachydermWeb.ElephantBrowser, which
has the same namespace, then this property value should be set to PachydermWeb.ElephantBrowser.ElephantDriver, PachydermWeb.ElephantBrowser
.
Remarks
This property value is mandatory on all instances of web driver configuration. The type indicated here must derive from OpenQA.Selenium.IWebDriver.
For WebDriver implementations which are shipped with Selenium, all that is required is the
simple type name.
For WebDriver implementations that are not part of the Selenium.WebDriver
NuGet package,
this should be an assembly-qualified type name, such that the type could be located with
GetType(string).
When this value is either RemoteWebDriver
, or when it is set to a WebDriver which is not part
of the Selenium.WebDriver
NuGet package, then OptionsType must also be set.
For local drivers which are shipped with Selenium, explicitly setting the options type is not neccesary;
this library will automatically select the appropriate type.
- See Also
GridUrl
Applicable to remote web drivers only, gets or sets the URL at which the Selenium Grid is hosted.
public string GridUrl { get; set; }
Property Value
Remarks
The value of this property is unused and irrelevant if DriverType is not set to
RemoteWebDriver
.
When using a remote web driver, it is usually required to set this property value. The only time a value is not required is if your Selenium Grid configuration is occupying the default URL, which is unlikely in a production configuration.
OptionsCustomizer
An optional object which implements ICustomizesOptions<TOptions> for the corresponding OpenQA.Selenium.DriverOptions type for the DriverType/OptionsType.
public object OptionsCustomizer { get; set; }
Property Value
Remarks
If this instance is bound from a configuration file - such as appsettings.json
- then this property is bound from a configuration key named
OptionsCustomizerType
rather than "OptionsCustomizer". The value of that configuration key should be the assembly-qualified type name of
the concrete implementation of ICustomizesOptions<TOptions> which should be used to customize the options. In this scenario this type
must also have a public parameterless constructor.
This configuration property is rarely required. This object is used to customize the options for creating a web driver after OptionsFactory has created the options instance but before it is used to create the web driver.
This is useful when you need to customize the options for a web driver in a way which is not supported by the binding from a configuration file. For example, some web driver options do not provide property getters/setters but must be configured using methods. In this case you can implement this interface with a class to customize the options as required.
OptionsFactory
Gets or sets a function which creates the object which derives from OpenQA.Selenium.DriverOptions, used as the creation options for the OpenQA.Selenium.IWebDriver.
public Func<DriverOptions> OptionsFactory { get; set; }
Property Value
- Func<DriverOptions>
Remarks
In the most common scenario - providing WebDriver options from a JSON configuration file such as appsettings.json
- this property is bound
from a configuration key named Options
, rather than "OptionsFactory". In a configuration file, the options are specified as a simple
JSON object. However, after binding to this property this becomes a factory function instead. That is because of two factors:
- Instances of types which derive from OpenQA.Selenium.DriverOptions are not reusable and should not be shared between WebDriver instances
- This WebDriver factory framework must be capable of creating multiple OpenQA.Selenium.IWebDriver instances from one configuration, thus requiring many options instances
The return value of this function must be an object of an appropriate type to match the implementation of OpenQA.Selenium.IWebDriver that is selected, via DriverType. If this value was bound from a configuration file then the generated factory function will automatically instantiate an instance of either:
- The options type specified in the configuration file, if OptionsType is set
- The options type which is inferred from the DriverType, if OptionsType is not set. See the documentation for OptionsType for more information
OptionsType
Gets or sets a value indicating the concrete Type of the options object which should be provded to the WebDriver when the driver is created.
public string OptionsType { get; set; }
Property Value
Remarks
This value only needs to be provided in two scenarios:
- When the DriverType is set to
RemoteWebDriver
- When the DriverType is set to a driver implementation which is not
shipped with Selenium in the
Selenium.WebDriver
NuGet package
For local WebDriver implementations which are shipped with Selenium, this library will automatically select and use the appropriate options type if this property is null.
In a similar manner to DriverType, if
- See Also