Skip to content

Commit

Permalink
[dotnet] Add dispose on constructor failure to ensure driver closes (#…
Browse files Browse the repository at this point in the history
…13673)

* Forced Dispose of driver on chromedriver exception

* Changed try-catch to only envelop StartSession and moved driver Quit command to own function

* Remove extra spaces

* Undo DriverDispose changes and instead call quit

---------

Co-authored-by: Nikolay Borisenko <[email protected]>
  • Loading branch information
MASACR99 and nvborisenko authored Mar 15, 2024
1 parent 2f0a93d commit 4c0ac3d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions dotnet/src/webdriver/WebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,18 @@ public class WebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFinds
protected WebDriver(ICommandExecutor executor, ICapabilities capabilities)
{
this.executor = executor;
this.StartSession(capabilities);

try
{
this.StartSession(capabilities);
}
catch (Exception)
{
// Failed to start driver session, disposing of driver
this.Quit();
throw;
}

this.elementFactory = new WebElementFactory(this);
this.network = new NetworkManager(this);
this.registeredCommands.AddRange(DriverCommand.KnownCommands);
Expand Down Expand Up @@ -692,7 +703,6 @@ protected virtual void Dispose(bool disposing)
{
this.sessionId = null;
}

this.executor.Dispose();
}

Expand Down

0 comments on commit 4c0ac3d

Please sign in to comment.