Skip to content

Commit 7810cf3

Browse files
committed
Handle nullability for session Id in WebDriver
1 parent a9cc9d6 commit 7810cf3

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

dotnet/src/webdriver/WebDriver.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using System.Collections;
2525
using System.Collections.Generic;
2626
using System.Collections.ObjectModel;
27+
using System.Diagnostics.CodeAnalysis;
2728
using System.Globalization;
2829
using 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(this.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>();
@@ -681,7 +680,7 @@ protected void StartSession(ICapabilities capabilities)
681680
this.capabilities = returnedCapabilities;
682681

683682
string sessionId = response.SessionId ?? throw new WebDriverException("StartSession did not return a sessionId");
684-
this.sessionId = new SessionId(sessionId);
683+
this.SessionId = new SessionId(sessionId);
685684
}
686685

687686
/// <summary>
@@ -725,7 +724,7 @@ protected virtual void Dispose(bool disposing)
725724
{
726725
try
727726
{
728-
if (this.sessionId is not null)
727+
if (this.SessionId is not null)
729728
{
730729
this.Execute(DriverCommand.Quit, null);
731730
}
@@ -741,7 +740,7 @@ protected virtual void Dispose(bool disposing)
741740
}
742741
finally
743742
{
744-
this.sessionId = null;
743+
this.SessionId = null;
745744
}
746745
this.executor.Dispose();
747746
}

0 commit comments

Comments
 (0)