Actually, I have now solved this using some input from here: http://4byte.cn/question/1068133/get-session-id-for-a-selenium-remotewebdriver-in-c.html
Subclass RemoteWebDriver (seems to be the only way to get the session id):
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Specflow_Selenium_PO_Example2.Utils
{
class CustomRemoteDriver : RemoteWebDriver
{
CustomRemoteDriver(ICapabilities desiredCapabilities) : base(desiredCapabilities)
{
}
public CustomRemoteDriver(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities):base(commandExecutor, desiredCapabilities)
{
}
public CustomRemoteDriver(Uri remoteAddress, ICapabilities desiredCapabilities):base(remoteAddress, desiredCapabilities)
{
}
public CustomRemoteDriver(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout):base(remoteAddress, desiredCapabilities, commandTimeout)
{
}
public string GetSessionId()
{
return base.SessionId.ToString();
}
}
}
I'm using Specflow, so in my Hooks class (and because I execute tests locally as well (this could also just be put into the standard tearDown method for standard selenium tests):
static IWebDriver localDriver;
static CustomRemoteDriver driver;
...
In the teardown method:
...
if (host == "saucelabs")
{
bool passed = TestContext.CurrentContext.Result.Status == TestStatus.Passed;
try
{
// Logs the result to Sauce Labs
((IJavaScriptExecutor)driver).ExecuteScript("sauce:job-result=" + (passed ? "passed" : "failed"));
// Sauce labs results are reported back to the Jenkins job
string message = string.Format("SauceOnDemandSessionID=%1$s job-name=%2$s", driver.GetSessionId().ToString(),"some jobs name");
Console.Write(message);
}
finally
{
driver.Quit();
}
...
@markwinspear
Incidentally, as to the "but Java exposes it" argument, .NET is *not* Java. The .NET bindings should not be the Java bindings. There are differing philosophies between the languages. The .NET bindings are intended to be a building block on which to build your solution; not the full end-all-be-all solution itself. This philosophy extends to the base bindings, where things are made available to be subclasses, as well as to the support library (WebDriver.Support.dll), which I from time to time regret creating at all, as users tend to see it as the definitive, canonical solution, instead of suggestions and examples of how to proceed.
Does that answer your question?
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a2742d27-3a9c-4912-a447-71d1fa96b439%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/7b4d220f-26bd-4e4a-8e46-ecf2008316e8%40googlegroups.com.
I'll add exposing the session ID to the .NET bindings soon, hidden behind a role-based interface (i.e. you'll have to cast your variable). I *won't* be replying to this thread any longer, and my presence on the mailing list will be diminished going forward. I might continue to maintain the .NET bindings and IE driver going forward; I haven't decided on that yet.
To my U.S.-based colleagues on this list, I wish you a Happy Thanksgiving holiday, and I hope you enjoy your time with whomever you decide to spend it. The jury is still out as to whether I will be able to, after this.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/be67aeea-d24b-4cfe-8826-f259ef89c753%40googlegroups.com.