2525using System . Text ;
2626using System . Text . Json ;
2727using System . Text . Json . Serialization ;
28+ using static OpenQA . Selenium . SeleniumManagerResponse ;
2829
2930#nullable enable
3031
@@ -69,6 +70,7 @@ public static class SeleniumManager
6970 {
7071 throw new WebDriverException ( $ "Unable to locate or obtain Selenium Manager binary at { binaryFullPath } ") ;
7172 }
73+
7274 return binaryFullPath ;
7375 } ) ;
7476
@@ -79,7 +81,7 @@ public static class SeleniumManager
7981 /// <returns>
8082 /// An array with two entries, one for the driver path, and another one for the browser path.
8183 /// </returns>
82- public static Dictionary < string , string ? > BinaryPaths ( string arguments )
84+ public static Dictionary < string , string > BinaryPaths ( string arguments )
8385 {
8486 StringBuilder argsBuilder = new StringBuilder ( arguments ) ;
8587 argsBuilder . Append ( " --language-binding csharp" ) ;
@@ -90,7 +92,7 @@ public static class SeleniumManager
9092 }
9193
9294 var smCommandResult = RunCommand ( _lazyBinaryFullPath . Value , argsBuilder . ToString ( ) ) ;
93- Dictionary < string , string ? > binaryPaths = new ( )
95+ Dictionary < string , string > binaryPaths = new ( )
9496 {
9597 { "browser_path" , smCommandResult . BrowserPath } ,
9698 { "driver_path" , smCommandResult . DriverPath }
@@ -113,7 +115,7 @@ public static class SeleniumManager
113115 /// <returns>
114116 /// the standard output of the execution.
115117 /// </returns>
116- private static SeleniumManagerResponse . ResultResponse RunCommand ( string fileName , string arguments )
118+ private static ResultResponse RunCommand ( string fileName , string arguments )
117119 {
118120 Process process = new Process ( ) ;
119121 process . StartInfo . FileName = _lazyBinaryFullPath . Value ;
@@ -184,8 +186,7 @@ private static SeleniumManagerResponse.ResultResponse RunCommand(string fileName
184186
185187 try
186188 {
187- jsonResponse = JsonSerializer . Deserialize < SeleniumManagerResponse > ( output , _serializerOptions )
188- ?? throw new WebDriverException ( "SeleniumManagerResponse was null" ) ;
189+ jsonResponse = JsonSerializer . Deserialize < SeleniumManagerResponse > ( output , _serializerOptions ) ! ;
189190 }
190191 catch ( Exception ex )
191192 {
@@ -196,7 +197,7 @@ private static SeleniumManagerResponse.ResultResponse RunCommand(string fileName
196197 {
197198 foreach ( var entry in jsonResponse . Logs )
198199 {
199- switch ( entry ? . Level )
200+ switch ( entry . Level )
200201 {
201202 case "WARN" :
202203 if ( _logger . IsEnabled ( LogEventLevel . Warn ) )
@@ -220,35 +221,24 @@ private static SeleniumManagerResponse.ResultResponse RunCommand(string fileName
220221 }
221222 }
222223
223- return jsonResponse . Result ?? throw new WebDriverException ( "Selenium manager response's Result was null" ) ;
224+ return jsonResponse . Result ;
224225 }
225226 }
226227
227- internal class SeleniumManagerResponse
228+ internal record SeleniumManagerResponse ( IReadOnlyList < LogEntryResponse > Logs , ResultResponse Result )
228229 {
229- public IReadOnlyList < LogEntryResponse ? > ? Logs { get ; set ; }
230-
231- public ResultResponse ? Result { get ; set ; }
232-
233- public class LogEntryResponse
234- {
235- public string ? Level { get ; set ; }
230+ public record LogEntryResponse ( string Level , string Message ) ;
236231
237- public string ? Message { get ; set ; }
238- }
239-
240- public class ResultResponse
232+ public record ResultResponse ( string DriverPath , string BrowserPath )
241233 {
242234 [ JsonPropertyName ( "driver_path" ) ]
243- public string ? DriverPath { get ; set ; }
235+ public string DriverPath { get ; } = DriverPath ;
244236
245237 [ JsonPropertyName ( "browser_path" ) ]
246- public string ? BrowserPath { get ; set ; }
238+ public string BrowserPath { get ; } = BrowserPath ;
247239 }
248240 }
249241
250242 [ JsonSerializable ( typeof ( SeleniumManagerResponse ) ) ]
251- internal partial class SeleniumManagerSerializerContext : JsonSerializerContext
252- {
253- }
243+ internal partial class SeleniumManagerSerializerContext : JsonSerializerContext ;
254244}
0 commit comments