2424using  System . Collections ; 
2525using  System . Collections . Generic ; 
2626using  System . Collections . ObjectModel ; 
27+ using  System . Diagnostics . CodeAnalysis ; 
2728using  System . Globalization ; 
2829using  System . Threading . Tasks ; 
2930
@@ -44,7 +45,7 @@ public class WebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFinds
4445        private  IFileDetector  fileDetector  =  new  DefaultFileDetector ( ) ; 
4546        private  NetworkManager  network ; 
4647        private  WebElementFactory  elementFactory ; 
47-          private   SessionId   sessionId ; 
48+ 
4849        private  List < string >  registeredCommands  =  new  List < string > ( ) ; 
4950
5051        /// <summary> 
@@ -191,10 +192,7 @@ public bool IsActionExecutor
191192        /// <summary> 
192193        /// Gets the <see cref="SessionId"/> for the current session of this driver. 
193194        /// </summary> 
194-         public  SessionId  SessionId 
195-         { 
196-             get  {  return  this . sessionId ;  } 
197-         } 
195+         public  SessionId  SessionId  {  get ;  private  set ;  } 
198196
199197        /// <summary> 
200198        /// Gets or sets the <see cref="IFileDetector"/> responsible for detecting 
@@ -612,7 +610,7 @@ protected virtual Response Execute(string driverCommandToExecute,
612610        /// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns> 
613611        protected  virtual  async  Task < Response >  ExecuteAsync ( string  driverCommandToExecute ,  Dictionary < string ,  object >  parameters ) 
614612        { 
615-             Command  commandToExecute  =  new  Command ( this . sessionId ,  driverCommandToExecute ,  parameters ) ; 
613+             Command  commandToExecute  =  new  Command ( SessionId ,  driverCommandToExecute ,  parameters ) ; 
616614
617615            Response  commandResponse ; 
618616
@@ -641,6 +639,7 @@ protected virtual async Task<Response> ExecuteAsync(string driverCommandToExecut
641639        /// Starts a session with the driver 
642640        /// </summary> 
643641        /// <param name="capabilities">Capabilities of the browser</param> 
642+         [ MemberNotNull ( nameof ( SessionId ) ) ] 
644643        protected  void  StartSession ( ICapabilities  capabilities ) 
645644        { 
646645            Dictionary < string ,  object >  parameters  =  new  Dictionary < string ,  object > ( ) ; 
@@ -679,7 +678,9 @@ protected void StartSession(ICapabilities capabilities)
679678
680679            ReturnedCapabilities  returnedCapabilities  =  new  ReturnedCapabilities ( rawCapabilities ) ; 
681680            this . capabilities  =  returnedCapabilities ; 
682-             this . sessionId  =  new  SessionId ( response . SessionId ) ; 
681+ 
682+             string  sessionId  =  response . SessionId  ??  throw  new  WebDriverException ( $ "The remote end did not respond with ID of a session when it was required. { response . Value } ") ; 
683+             this . SessionId  =  new  SessionId ( sessionId ) ; 
683684        } 
684685
685686        /// <summary> 
@@ -723,7 +724,7 @@ protected virtual void Dispose(bool disposing)
723724        { 
724725            try 
725726            { 
726-                 if  ( this . sessionId  is  not null ) 
727+                 if  ( this . SessionId  is  not null ) 
727728                { 
728729                    this . Execute ( DriverCommand . Quit ,  null ) ; 
729730                } 
@@ -739,7 +740,7 @@ protected virtual void Dispose(bool disposing)
739740            } 
740741            finally 
741742            { 
742-                 this . sessionId  =  null ; 
743+                 this . SessionId  =  null ; 
743744            } 
744745            this . executor . Dispose ( ) ; 
745746        } 
0 commit comments