A base class representing a driver for a web browser.
| 31 | /// A base class representing a driver for a web browser. |
| 32 | /// </summary> |
| 33 | public class WebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFindsElement, ITakesScreenshot, ISupportsPrint, IActionExecutor, IAllowsFileDetection, IHasCapabilities, IHasCommandExecutor, IHasSessionId, ICustomDriverCommandExecutor, IHasVirtualAuthenticator |
| 34 | { |
| 35 | /// <summary> |
| 36 | /// The default command timeout for HTTP requests in a RemoteWebDriver instance. |
| 37 | /// </summary> |
| 38 | protected static readonly TimeSpan DefaultCommandTimeout = TimeSpan.FromSeconds(60); |
| 39 | private IFileDetector fileDetector = new DefaultFileDetector(); |
| 40 | private NetworkManager? network; |
| 41 | private WebElementFactory elementFactory; |
| 42 | |
| 43 | private readonly List<string> registeredCommands = new List<string>(); |
| 44 | |
| 45 | /// <summary> |
| 46 | /// Initializes a new instance of the <see cref="WebDriver"/> class. |
| 47 | /// </summary> |
| 48 | /// <param name="executor">The <see cref="ICommandExecutor"/> object used to execute commands.</param> |
| 49 | /// <param name="capabilities">The <see cref="ICapabilities"/> object used to configure the driver session.</param> |
| 50 | protected WebDriver(ICommandExecutor executor, ICapabilities capabilities) |
| 51 | { |
| 52 | this.CommandExecutor = executor; |
| 53 | this.elementFactory = new WebElementFactory(this); |
| 54 | this.registeredCommands.AddRange(DriverCommand.KnownCommands); |
| 55 | |
| 56 | if (this is ISupportsLogs) |
| 57 | { |
| 58 | // Only add the legacy log commands if the driver supports |
| 59 | // retrieving the logs via the extension end points. |
| 60 | this.RegisterDriverCommand(DriverCommand.GetAvailableLogTypes, new HttpCommandInfo(HttpCommandInfo.GetCommand, "/session/{sessionId}/se/log/types"), true); |
| 61 | this.RegisterDriverCommand(DriverCommand.GetLog, new HttpCommandInfo(HttpCommandInfo.PostCommand, "/session/{sessionId}/se/log"), true); |
| 62 | } |
| 63 | |
| 64 | try |
| 65 | { |
| 66 | this.StartSession(capabilities); |
| 67 | } |
| 68 | catch (Exception) |
| 69 | { |
| 70 | try |
| 71 | { |
| 72 | // Failed to start driver session, disposing of driver |
| 73 | this.Dispose(); |
| 74 | } |
| 75 | catch |
| 76 | { |
| 77 | // Ignore the clean-up exception. We'll propagate the original failure. |
| 78 | } |
| 79 | throw; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /// <summary> |
| 84 | /// Gets the <see cref="ICommandExecutor"/> which executes commands for this driver. |
| 85 | /// </summary> |
| 86 | public ICommandExecutor CommandExecutor { get; } |
| 87 | |
| 88 | /// <summary> |
| 89 | /// Gets the <see cref="ICapabilities"/> that the driver session was created with, which may be different from those requested. |
| 90 | /// </summary> |
nothing calls this directly
no test coverage detected