@@ -68,6 +68,9 @@ public class SafariDriver : WebDriver
6868 private const string GetPermissionsCommand = "getPermissions" ;
6969 private const string SetPermissionsCommand = "setPermissions" ;
7070
71+ private readonly SafariDriverService driverService ;
72+ private readonly bool disposeDriverService ;
73+
7174 /// <summary>
7275 /// Initializes a new instance of the <see cref="SafariDriver"/> class.
7376 /// </summary>
@@ -123,7 +126,7 @@ public SafariDriver(string safariDriverDirectory, SafariOptions options)
123126 /// <param name="options">The <see cref="SafariOptions"/> to be used with the Safari driver.</param>
124127 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
125128 public SafariDriver ( string safariDriverDirectory , SafariOptions options , TimeSpan commandTimeout )
126- : this ( SafariDriverService . CreateDefaultService ( safariDriverDirectory ) , options , commandTimeout )
129+ : this ( SafariDriverService . CreateDefaultService ( safariDriverDirectory ) , disposeService : true , options , commandTimeout )
127130 {
128131 }
129132
@@ -145,8 +148,16 @@ public SafariDriver(SafariDriverService service, SafariOptions options)
145148 /// <param name="options">The <see cref="SafariOptions"/> to be used with the Safari driver.</param>
146149 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
147150 public SafariDriver ( SafariDriverService service , SafariOptions options , TimeSpan commandTimeout )
151+ : this ( service , disposeService : false , options , commandTimeout )
152+ {
153+ }
154+
155+ private SafariDriver ( SafariDriverService service , bool disposeService , SafariOptions options , TimeSpan commandTimeout )
148156 : base ( StartDriverServiceCommandExecutor ( service , options , commandTimeout ) , ConvertOptionsToCapabilities ( options ) )
149157 {
158+ this . driverService = service ;
159+ this . disposeDriverService = disposeService ;
160+
150161 this . AddCustomSafariCommand ( AttachDebuggerCommand , HttpCommandInfo . PostCommand , "/session/{sessionId}/apple/attach_debugger" ) ;
151162 this . AddCustomSafariCommand ( GetPermissionsCommand , HttpCommandInfo . GetCommand , "/session/{sessionId}/apple/permissions" ) ;
152163 this . AddCustomSafariCommand ( SetPermissionsCommand , HttpCommandInfo . PostCommand , "/session/{sessionId}/apple/permissions" ) ;
@@ -231,6 +242,30 @@ public override IFileDetector FileDetector
231242 set { }
232243 }
233244
245+ /// <summary>
246+ /// Stops the driver from running
247+ /// </summary>
248+ /// <param name="disposing">if its in the process of disposing</param>
249+ protected override void Dispose ( bool disposing )
250+ {
251+ if ( disposing )
252+ {
253+ if ( this . SessionId is not null )
254+ {
255+ this . Execute ( DriverCommand . Quit , null ) ;
256+
257+ this . SessionId = null ;
258+ }
259+
260+ if ( this . disposeDriverService )
261+ {
262+ this . driverService . Dispose ( ) ;
263+ }
264+ }
265+
266+ base . Dispose ( disposing ) ;
267+ }
268+
234269 private static ICapabilities ConvertOptionsToCapabilities ( SafariOptions options )
235270 {
236271 if ( options == null )
0 commit comments