I'm trying to get a session id for a test being run on the SauceLabs cloud, but I can't seem to access it.
I've tried the following approaches:
//Returns null
var sessionId = (string)((RemoteWebDriver)driver).Capabilities.GetCapability("webdriver.remote.sessionid");
//Will not compile
sessionId = ((RemoteWebDriver)driver).SessionId; //This is protected.
The second approach is particularly confusing. It's a protected property, but if I can only access this from a derived class, then it's essentially useless for what I need.
Any help is appreciated.
In order for this to work, I had to create a class derived from RemoteWebDriver
and then define a getter method. For example:
class CustomeRemoteDriver : RemoteWebDriver
{
public CustomeRemoteDriver(ICapabilities desiredCapabilities):base(desiredCapabilities)
{
}
public CustomeRemoteDriver(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities):base(commandExecutor, desiredCapabilities)
{
}
public CustomeRemoteDriver(Uri remoteAddress, ICapabilities desiredCapabilities):base(remoteAddress, desiredCapabilities)
{
}
public CustomeRemoteDriver(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout):base(remoteAddress, desiredCapabilities, commandTimeout)
{
}
public string GetSessionId()
{
return base.SessionId.ToString();
}
}
Casting
issue can you post what the actual error is it's hard to see the little image you have posted – Mordentpublic CustomRemoteDriver(Uri uri, DesiredCapabilities capabilities) : base(uri, capabilities) { } public SessionId getExecutionID() { return ((CustomRemoteDriver)Driver.Browser.driver).SessionId; } }
– Mordent