Skip to content

Commit 076e763

Browse files
committed
Exposing session ID property on RemoteWebDriver in .NET bindings
Users can now cast their driver instance to IHasSessionId to access the SessionId property, which returns a SessionId object. To use the SessionId object with external tools, simply call the ToString() method on the instance. Note that relying on the SessionId for anything is probably a Bad Thing, because it introduces a leak in the abstraction of a driver. Please do not use this property; its introduction is the Wrong Approach, but it's being exposed at the insistence of a selection of users.
1 parent 4395a9b commit 076e763

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace OpenQA.Selenium.Remote
7+
{
8+
/// <summary>
9+
/// Interface indicating the driver has a Session ID.
10+
/// </summary>
11+
public interface IHasSessionId
12+
{
13+
/// <summary>
14+
/// Gets the session ID of the current session.
15+
/// </summary>
16+
SessionId SessionId { get; }
17+
}
18+
}

dotnet/src/webdriver/Remote/RemoteWebDriver.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace OpenQA.Selenium.Remote
6060
/// }
6161
/// </code>
6262
/// </example>
63-
public class RemoteWebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFindsById, IFindsByClassName, IFindsByLinkText, IFindsByName, IFindsByTagName, IFindsByXPath, IFindsByPartialLinkText, IFindsByCssSelector, ITakesScreenshot, IHasInputDevices, IHasCapabilities, IHasWebStorage, IHasLocationContext, IHasApplicationCache, IAllowsFileDetection
63+
public class RemoteWebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFindsById, IFindsByClassName, IFindsByLinkText, IFindsByName, IFindsByTagName, IFindsByXPath, IFindsByPartialLinkText, IFindsByCssSelector, ITakesScreenshot, IHasInputDevices, IHasCapabilities, IHasWebStorage, IHasLocationContext, IHasApplicationCache, IAllowsFileDetection, IHasSessionId
6464
{
6565
/// <summary>
6666
/// The default command timeout for HTTP requests in a RemoteWebDriver instance.
@@ -392,6 +392,14 @@ public virtual IFileDetector FileDetector
392392
}
393393
}
394394

395+
/// <summary>
396+
/// Gets the <see cref="SessionId"/> for the current session of this driver.
397+
/// </summary>
398+
public SessionId SessionId
399+
{
400+
get { return this.sessionId; }
401+
}
402+
395403
/// <summary>
396404
/// Gets a value indicating whether or not the driver is compliant with the W3C WebDriver specification.
397405
/// </summary>
@@ -408,14 +416,6 @@ protected ICommandExecutor CommandExecutor
408416
get { return this.executor; }
409417
}
410418

411-
/// <summary>
412-
/// Gets the <see cref="SessionId"/> for the current session of this driver.
413-
/// </summary>
414-
protected SessionId SessionId
415-
{
416-
get { return this.sessionId; }
417-
}
418-
419419
/// <summary>
420420
/// Finds the first element in the page that matches the <see cref="By"/> object
421421
/// </summary>

dotnet/src/webdriver/WebDriver.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<Compile Include="IE\InternetExplorerDriverEngine.cs" />
103103
<Compile Include="IFileDetector.cs" />
104104
<Compile Include="Html5\IHasLocationContext.cs" />
105+
<Compile Include="Remote\IHasSessionId.cs" />
105106
<Compile Include="IHasTouchScreen.cs" />
106107
<Compile Include="Interactions\ScreenMoveAction.cs" />
107108
<Compile Include="Interactions\ScreenReleaseAction.cs" />

0 commit comments

Comments
 (0)