Skip to content

Commit 4c0ac3d

Browse files
[dotnet] Add dispose on constructor failure to ensure driver closes (#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]>
1 parent 2f0a93d commit 4c0ac3d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

dotnet/src/webdriver/WebDriver.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,18 @@ public class WebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFinds
5454
protected WebDriver(ICommandExecutor executor, ICapabilities capabilities)
5555
{
5656
this.executor = executor;
57-
this.StartSession(capabilities);
57+
58+
try
59+
{
60+
this.StartSession(capabilities);
61+
}
62+
catch (Exception)
63+
{
64+
// Failed to start driver session, disposing of driver
65+
this.Quit();
66+
throw;
67+
}
68+
5869
this.elementFactory = new WebElementFactory(this);
5970
this.network = new NetworkManager(this);
6071
this.registeredCommands.AddRange(DriverCommand.KnownCommands);
@@ -692,7 +703,6 @@ protected virtual void Dispose(bool disposing)
692703
{
693704
this.sessionId = null;
694705
}
695-
696706
this.executor.Dispose();
697707
}
698708

0 commit comments

Comments
 (0)