Skip to content

Commit

Permalink
[dotnet] Fix protocol cdp version for remote webdriver (#13507)
Browse files Browse the repository at this point in the history
* Amend protocol cdp version for remote webdriver

* Don't parse protocol version if it is specified by user
  • Loading branch information
nvborisenko authored Feb 2, 2024
1 parent 249e291 commit 5c214ba
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions dotnet/src/webdriver/Remote/RemoteWebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,25 +433,36 @@ public DevToolsSession GetDevToolsSession()
/// <returns>The active session to use to communicate with the Developer Tools debugging protocol.</returns>
public DevToolsSession GetDevToolsSession(DevToolsOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}

if (this.devToolsSession == null)
{
if (!this.Capabilities.HasCapability(RemoteDevToolsEndPointCapabilityName))
{
throw new WebDriverException("Cannot find " + RemoteDevToolsEndPointCapabilityName + " capability for driver");
}

if (!this.Capabilities.HasCapability(RemoteDevToolsVersionCapabilityName))
{
throw new WebDriverException("Cannot find " + RemoteDevToolsVersionCapabilityName + " capability for driver");
}

string debuggerAddress = this.Capabilities.GetCapability(RemoteDevToolsEndPointCapabilityName).ToString();
string version = this.Capabilities.GetCapability(RemoteDevToolsVersionCapabilityName).ToString();

bool versionParsed = int.TryParse(version.Substring(0, version.IndexOf(".")), out int devToolsProtocolVersion);
if (!versionParsed)
if (!options.ProtocolVersion.HasValue || options.ProtocolVersion == DevToolsSession.AutoDetectDevToolsProtocolVersion)
{
throw new WebDriverException("Cannot parse protocol version from reported version string: " + version);
if (!this.Capabilities.HasCapability(RemoteDevToolsVersionCapabilityName))
{
throw new WebDriverException("Cannot find " + RemoteDevToolsVersionCapabilityName + " capability for driver");
}

string version = this.Capabilities.GetCapability(RemoteDevToolsVersionCapabilityName).ToString();

bool versionParsed = int.TryParse(version.Substring(0, version.IndexOf(".")), out int devToolsProtocolVersion);
if (!versionParsed)
{
throw new WebDriverException("Cannot parse protocol version from reported version string: " + version);
}

options.ProtocolVersion = devToolsProtocolVersion;
}

try
Expand Down

0 comments on commit 5c214ba

Please sign in to comment.