|
19 | 19 | using System;
|
20 | 20 | using System.Collections.Generic;
|
21 | 21 | using System.Collections.ObjectModel;
|
| 22 | +using OpenQA.Selenium.DevTools; |
22 | 23 | using OpenQA.Selenium.Html5;
|
23 | 24 | using OpenQA.Selenium.Internal;
|
24 | 25 |
|
@@ -57,13 +58,14 @@ namespace OpenQA.Selenium.Remote
|
57 | 58 | /// }
|
58 | 59 | /// </code>
|
59 | 60 | /// </example>
|
60 |
| - public class RemoteWebDriver : WebDriver, IFindsById, IFindsByClassName, IFindsByLinkText, IFindsByName, IFindsByTagName, IFindsByXPath, IFindsByPartialLinkText, IFindsByCssSelector |
| 61 | + public class RemoteWebDriver : WebDriver, IDevTools, IFindsById, IFindsByClassName, IFindsByLinkText, IFindsByName, IFindsByTagName, IFindsByXPath, IFindsByPartialLinkText, IFindsByCssSelector |
61 | 62 | {
|
| 63 | + public readonly string RemoteDevToolsEndPointCapabilityName = "se:cdp"; |
| 64 | + public readonly string RemoteDevToolsVersionCapabilityName = "se:cdpVersion"; |
| 65 | + |
62 | 66 | private const string DefaultRemoteServerUrl = "http://127.0.0.1:4444/wd/hub";
|
63 | 67 |
|
64 |
| - private IWebStorage storage; |
65 |
| - private IApplicationCache appCache; |
66 |
| - private ILocationContext locationContext; |
| 68 | + private DevToolsSession devToolsSession; |
67 | 69 |
|
68 | 70 | /// <summary>
|
69 | 71 | /// Initializes a new instance of the <see cref="RemoteWebDriver"/> class. This constructor defaults proxy to http://127.0.0.1:4444/wd/hub
|
@@ -399,6 +401,49 @@ public ReadOnlyCollection<IWebElement> FindElementsByCssSelector(string cssSelec
|
399 | 401 | return this.FindElements("css selector", cssSelector);
|
400 | 402 | }
|
401 | 403 |
|
| 404 | + public DevToolsSession GetDevToolsSession() |
| 405 | + { |
| 406 | + return GetDevToolsSession(DevToolsSession.AutoDetectDevToolsProtocolVersion); |
| 407 | + } |
| 408 | + |
| 409 | + public DevToolsSession GetDevToolsSession(int protocolVersion) |
| 410 | + { |
| 411 | + if (this.devToolsSession == null) |
| 412 | + { |
| 413 | + if (!this.Capabilities.HasCapability(RemoteDevToolsEndPointCapabilityName)) |
| 414 | + { |
| 415 | + throw new WebDriverException("Cannot find " + RemoteDevToolsEndPointCapabilityName + " capability for driver"); |
| 416 | + } |
| 417 | + |
| 418 | + if (!this.Capabilities.HasCapability(RemoteDevToolsVersionCapabilityName)) |
| 419 | + { |
| 420 | + throw new WebDriverException("Cannot find " + RemoteDevToolsVersionCapabilityName + " capability for driver"); |
| 421 | + } |
| 422 | + |
| 423 | + string debuggerAddress = this.Capabilities.GetCapability(RemoteDevToolsEndPointCapabilityName).ToString(); |
| 424 | + string version = this.Capabilities.GetCapability(RemoteDevToolsVersionCapabilityName).ToString(); |
| 425 | + |
| 426 | + bool versionParsed = int.TryParse(version.Substring(0, version.IndexOf(".")), out int devToolsProtocolVersion); |
| 427 | + if (!versionParsed) |
| 428 | + { |
| 429 | + throw new WebDriverException("Cannot parse protocol version from reported version string: " + version); |
| 430 | + } |
| 431 | + |
| 432 | + try |
| 433 | + { |
| 434 | + DevToolsSession session = new DevToolsSession(debuggerAddress); |
| 435 | + session.Start(devToolsProtocolVersion).ConfigureAwait(false).GetAwaiter().GetResult(); |
| 436 | + this.devToolsSession = session; |
| 437 | + } |
| 438 | + catch (Exception e) |
| 439 | + { |
| 440 | + throw new WebDriverException("Unexpected error creating WebSocket DevTools session.", e); |
| 441 | + } |
| 442 | + } |
| 443 | + |
| 444 | + return this.devToolsSession; |
| 445 | + } |
| 446 | + |
402 | 447 | private static ICapabilities ConvertOptionsToCapabilities(DriverOptions options)
|
403 | 448 | {
|
404 | 449 | if (options == null)
|
|
0 commit comments