You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
thrownewArgumentException($"The specified customizer type must implement {nameof(ICustomizesOptions<DriverOptions>)}<{optionsType.Name}>.",nameof(customizerTypeName));
Copy file name to clipboardExpand all lines: CSF.Extensions.WebDriver/Factories/WebDriverCreationOptions.cs
+40-12Lines changed: 40 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -94,29 +94,57 @@ public class WebDriverCreationOptions
94
94
publicstringGridUrl{get;set;}
95
95
96
96
/// <summary>
97
-
/// Gets or sets a factory object which can create instances of WebDriver options, to be provided to the WebDriver implementation.
97
+
/// Gets or sets a function which creates the object which derives from <see cref="DriverOptions"/>, used as the creation options for the <see cref="IWebDriver"/>.
98
98
/// </summary>
99
99
/// <remarks>
100
100
/// <para>
101
+
/// In the most common scenario - providing WebDriver options from a JSON configuration file such as <c>appsettings.json</c> - this property is bound
102
+
/// from a configuration key named <c>Options</c>, rather than "OptionsFactory". In a configuration file, the options are specified as a simple
103
+
/// JSON object. However, after binding to this property this becomes a factory function instead. That is because of two factors:
104
+
/// </para>
105
+
/// <list type="bullet">
106
+
/// <item><description>Instances of types which derive from <see cref="DriverOptions"/> are not reusable and should not be shared between WebDriver instances</description></item>
107
+
/// <item><description>This WebDriver factory framework must be capable of creating multiple <see cref="IWebDriver"/> instances from one configuration, thus
108
+
/// requiring many options instances</description></item>
109
+
/// When bound from a configuration file, the options object which would be returned from this factory function will have properties set
110
+
/// as specified in that configuration.
111
+
/// </list>
112
+
/// <para>
101
113
/// The return value of this function must be an object of an appropriate type to match the implementation of <see cref="IWebDriver"/>
102
114
/// that is selected, via <see cref="DriverType"/>.
103
-
/// When deserializing this value from configuration (such as an <c>appsettings.json</c> file), the <see cref="OptionsType"/>
104
-
/// will be used to select the appropriate polymorphic type to which the configuration should be bound.
105
-
/// For local WebDriver implementations which are shipped with Selenium, the options type need not be specified explicitly;
106
-
/// it will be inferred from the chosen driver type.
115
+
/// If this value was bound from a configuration file then the generated factory function will automatically instantiate an instance of either:
107
116
/// </para>
117
+
/// <list type="bullet">
118
+
/// <item><description>The options type specified in the configuration file, if <see cref="OptionsType"/> is set</description></item>
119
+
/// <item><description>The options type which is inferred from the <see cref="DriverType"/>, if <see cref="OptionsType"/> is not set.
120
+
/// See the documentation for <see cref="OptionsType"/> for more information</description></item>
121
+
/// </list>
122
+
/// </remarks>
123
+
publicFunc<DriverOptions>OptionsFactory{get;set;}
124
+
125
+
/// <summary>
126
+
/// An optional object which implements <see cref="ICustomizesOptions{TOptions}"/> for the corresponding <see cref="DriverOptions"/>
127
+
/// type for the <see cref="DriverType"/>/<see cref="OptionsType"/>.
128
+
/// </summary>
129
+
/// <remarks>
108
130
/// <para>
109
-
/// This option is provided as a factory, rather than an instance of <see cref="DriverOptions"/> because it will create options
110
-
/// instances for - potentially - many usages throughout the application/test lifetime. It is a poor design choice to use a single
111
-
/// options instance for every one of the WebDriver instances which will be used. In some cases, this would cause functional issues,
112
-
/// such as where additional per-scenario capabilities need to be injected into each options instance.
131
+
/// If this instance is bound from a configuration file - such as <c>appsettings.json</c> - then this property is bound from a configuration key named
132
+
/// <c>OptionsCustomizerType</c> rather than "OptionsCustomizer". The value of that configuration key should be the assembly-qualified type name of
133
+
/// the concrete implementation of <see cref="ICustomizesOptions{TOptions}"/> which should be used to customize the options. In this scenario this type
134
+
/// must also have a public parameterless constructor.
113
135
/// </para>
114
136
/// <para>
115
-
/// Please note that when using Microsoft.Extensions.Configuration to bind an instance of this type, this factory function is bound
116
-
/// from an <see cref="IConfiguration"/> key named <c>Options</c> and not OptionsFactory as its member name might suggest.
137
+
/// This configuration property is rarely required. This object is used to customize the options for creating a web driver
138
+
/// after <see cref="OptionsFactory"/> has created the options instance but before it is used to
139
+
/// create the web driver.
140
+
/// </para>
141
+
/// <para>
142
+
/// 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
143
+
/// a configuration file. For example, some web driver options do not provide property getters/setters but must be configured
144
+
/// using methods. In this case you can implement this interface with a class to customize the options as required.
117
145
/// </para>
118
146
/// </remarks>
119
-
publicFunc<DriverOptions>OptionsFactory{get;set;}
147
+
publicobjectOptionsCustomizer{get;set;}
120
148
121
149
/// <summary>
122
150
/// Unneeded except in unusual circumstances, gets or sets the name of a type which is used to construct the WebDriver instance.
thrownewArgumentException($"The customizer type {customizer.GetType().FullName} does not implement {customizeGenericMethod.Name}<{typeof(TOptions).Name}>.",
53
+
nameof(customizer));
54
+
55
+
customizerInstance.CustomizeOptions(options);
56
+
}
57
+
37
58
/// <summary>
38
59
/// Initialises a new instance of <see cref="WebDriverFromOptionsFactory"/>.
0 commit comments