@@ -110,6 +110,8 @@ public class FirefoxDriver : WebDriver, IDevTools
110110 { GetFullPageScreenshotCommand , new HttpCommandInfo ( HttpCommandInfo . GetCommand , "/session/{sessionId}/moz/screenshot/full" ) }
111111 } ;
112112
113+ private FirefoxDriverService driverService ;
114+ private bool disposeDriverService ;
113115 private DevToolsSession devToolsSession ;
114116
115117 /// <summary>
@@ -125,7 +127,7 @@ public FirefoxDriver()
125127 /// </summary>
126128 /// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
127129 public FirefoxDriver ( FirefoxOptions options )
128- : this ( FirefoxDriverService . CreateDefaultService ( ) , options , RemoteWebDriver . DefaultCommandTimeout )
130+ : this ( FirefoxDriverService . CreateDefaultService ( ) , disposeService : true , options , RemoteWebDriver . DefaultCommandTimeout )
129131 {
130132 }
131133
@@ -167,7 +169,7 @@ public FirefoxDriver(string geckoDriverDirectory, FirefoxOptions options)
167169 /// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
168170 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
169171 public FirefoxDriver ( string geckoDriverDirectory , FirefoxOptions options , TimeSpan commandTimeout )
170- : this ( FirefoxDriverService . CreateDefaultService ( geckoDriverDirectory ) , options , commandTimeout )
172+ : this ( FirefoxDriverService . CreateDefaultService ( geckoDriverDirectory ) , disposeService : true , options , commandTimeout )
171173 {
172174 }
173175
@@ -188,8 +190,17 @@ public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options)
188190 /// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
189191 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
190192 public FirefoxDriver ( FirefoxDriverService service , FirefoxOptions options , TimeSpan commandTimeout )
193+ : this ( service , disposeService : false , options , commandTimeout )
194+ {
195+
196+ }
197+
198+ private FirefoxDriver ( FirefoxDriverService service , bool disposeService , FirefoxOptions options , TimeSpan commandTimeout )
191199 : base ( StartDriverServiceCommandExecutor ( service , options , commandTimeout ) , ConvertOptionsToCapabilities ( options ) )
192200 {
201+ this . driverService = service ;
202+ this . disposeDriverService = disposeService ;
203+
193204 // Add the custom commands unique to Firefox
194205 this . AddCustomFirefoxCommands ( ) ;
195206 }
@@ -477,6 +488,19 @@ protected override void Dispose(bool disposing)
477488 this . devToolsSession . Dispose ( ) ;
478489 this . devToolsSession = null ;
479490 }
491+
492+ if ( this . SessionId is not null )
493+ {
494+ this . Execute ( DriverCommand . Quit , null ) ;
495+
496+ this . SessionId = null ;
497+ }
498+
499+
500+ if ( this . disposeDriverService )
501+ {
502+ this . driverService . Dispose ( ) ;
503+ }
480504 }
481505
482506 base . Dispose ( disposing ) ;
0 commit comments