From e3aace6341455741c7214fc323a99fb1f067fe68 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Wed, 5 Feb 2025 00:53:52 -0500 Subject: [PATCH 1/2] [dotnet] Unify protected and internal Execute methods --- dotnet/src/webdriver/Alert.cs | 8 ++++---- dotnet/src/webdriver/CookieJar.cs | 10 ++++----- dotnet/src/webdriver/HttpCommandInfo.cs | 5 +++-- dotnet/src/webdriver/Logs.cs | 4 ++-- dotnet/src/webdriver/Navigator.cs | 8 ++++---- dotnet/src/webdriver/ShadowRoot.cs | 4 ++-- dotnet/src/webdriver/TargetLocator.cs | 16 +++++++-------- dotnet/src/webdriver/Timeouts.cs | 4 ++-- dotnet/src/webdriver/WebDriver.cs | 27 ++----------------------- dotnet/src/webdriver/WebElement.cs | 2 +- dotnet/src/webdriver/Window.cs | 14 ++++++------- 11 files changed, 40 insertions(+), 62 deletions(-) diff --git a/dotnet/src/webdriver/Alert.cs b/dotnet/src/webdriver/Alert.cs index d7637b7465a6b..f9ffd96fe9e43 100644 --- a/dotnet/src/webdriver/Alert.cs +++ b/dotnet/src/webdriver/Alert.cs @@ -47,7 +47,7 @@ public string? Text { get { - Response commandResponse = this.driver.InternalExecute(DriverCommand.GetAlertText, null); + Response commandResponse = this.driver.Execute(DriverCommand.GetAlertText, null); return (string?)commandResponse.Value; } } @@ -57,7 +57,7 @@ public string? Text /// public void Dismiss() { - this.driver.InternalExecute(DriverCommand.DismissAlert, null); + this.driver.Execute(DriverCommand.DismissAlert, null); } /// @@ -65,7 +65,7 @@ public void Dismiss() /// public void Accept() { - this.driver.InternalExecute(DriverCommand.AcceptAlert, null); + this.driver.Execute(DriverCommand.AcceptAlert, null); } /// @@ -83,7 +83,7 @@ public void SendKeys(string keysToSend) Dictionary parameters = new Dictionary(); parameters.Add("text", keysToSend); - this.driver.InternalExecute(DriverCommand.SetAlertValue, parameters); + this.driver.Execute(DriverCommand.SetAlertValue, parameters); } } } diff --git a/dotnet/src/webdriver/CookieJar.cs b/dotnet/src/webdriver/CookieJar.cs index 32674b24c4e43..86b3a823ddd67 100644 --- a/dotnet/src/webdriver/CookieJar.cs +++ b/dotnet/src/webdriver/CookieJar.cs @@ -34,7 +34,7 @@ public ReadOnlyCollection AllCookies { get { - Response response = driver.InternalExecute(DriverCommand.GetAllCookies, new Dictionary()); + Response response = driver.Execute(DriverCommand.GetAllCookies, new Dictionary()); List toReturn = new List(); if (response.Value is object?[] cookies) @@ -67,7 +67,7 @@ public void AddCookie(Cookie cookie) Dictionary parameters = new Dictionary(); parameters.Add("cookie", cookie); - driver.InternalExecute(DriverCommand.AddCookie, parameters); + driver.Execute(DriverCommand.AddCookie, parameters); } /// @@ -84,7 +84,7 @@ public void DeleteCookieNamed(string name) Dictionary parameters = new() { { "name", name } }; - driver.InternalExecute(DriverCommand.DeleteCookie, parameters); + driver.Execute(DriverCommand.DeleteCookie, parameters); } /// @@ -107,7 +107,7 @@ public void DeleteCookie(Cookie cookie) /// public void DeleteAllCookies() { - driver.InternalExecute(DriverCommand.DeleteAllCookies, null); + driver.Execute(DriverCommand.DeleteAllCookies, null); } /// @@ -125,7 +125,7 @@ public void DeleteAllCookies() try { - var rawCookie = driver.InternalExecute(DriverCommand.GetCookie, new() { { "name", name } }).Value; + var rawCookie = driver.Execute(DriverCommand.GetCookie, new() { { "name", name } }).Value; return Cookie.FromDictionary((Dictionary)rawCookie!); } diff --git a/dotnet/src/webdriver/HttpCommandInfo.cs b/dotnet/src/webdriver/HttpCommandInfo.cs index 36965d875cd5b..c3b013545fa54 100644 --- a/dotnet/src/webdriver/HttpCommandInfo.cs +++ b/dotnet/src/webdriver/HttpCommandInfo.cs @@ -51,10 +51,11 @@ public class HttpCommandInfo : CommandInfo /// /// Method of the Command /// Relative URL path to the resource used to execute the command + /// If or are . public HttpCommandInfo(string method, string resourcePath) { - this.ResourcePath = resourcePath; - this.Method = method; + this.ResourcePath = resourcePath ?? throw new ArgumentNullException(nameof(resourcePath)); + this.Method = method ?? throw new ArgumentNullException(nameof(method)); } /// diff --git a/dotnet/src/webdriver/Logs.cs b/dotnet/src/webdriver/Logs.cs index 91afcc03eb6cd..194a0161c5183 100644 --- a/dotnet/src/webdriver/Logs.cs +++ b/dotnet/src/webdriver/Logs.cs @@ -52,7 +52,7 @@ public ReadOnlyCollection AvailableLogTypes List availableLogTypes = new List(); try { - Response commandResponse = this.driver.InternalExecute(DriverCommand.GetAvailableLogTypes, null); + Response commandResponse = this.driver.Execute(DriverCommand.GetAvailableLogTypes, null); if (commandResponse.Value is object[] responseValue) { foreach (object logKind in responseValue) @@ -88,7 +88,7 @@ public ReadOnlyCollection GetLog(string logKind) Dictionary parameters = new Dictionary(); parameters.Add("type", logKind); - Response commandResponse = this.driver.InternalExecute(DriverCommand.GetLog, parameters); + Response commandResponse = this.driver.Execute(DriverCommand.GetLog, parameters); if (commandResponse.Value is object?[] responseValue) { diff --git a/dotnet/src/webdriver/Navigator.cs b/dotnet/src/webdriver/Navigator.cs index 4e50ec8ee8d29..a339114895b72 100644 --- a/dotnet/src/webdriver/Navigator.cs +++ b/dotnet/src/webdriver/Navigator.cs @@ -59,7 +59,7 @@ public void Back() /// A task object representing the asynchronous operation. public async Task BackAsync() { - await this.driver.InternalExecuteAsync(DriverCommand.GoBack, null).ConfigureAwait(false); + await this.driver.ExecuteAsync(DriverCommand.GoBack, null).ConfigureAwait(false); } /// @@ -79,7 +79,7 @@ public void Forward() /// A task object representing the asynchronous operation. public async Task ForwardAsync() { - await this.driver.InternalExecuteAsync(DriverCommand.GoForward, null).ConfigureAwait(false); + await this.driver.ExecuteAsync(DriverCommand.GoForward, null).ConfigureAwait(false); } /// @@ -112,7 +112,7 @@ public async Task GoToUrlAsync(string url) { { "url", url } }; - await this.driver.InternalExecuteAsync(DriverCommand.Get, parameters).ConfigureAwait(false); + await this.driver.ExecuteAsync(DriverCommand.Get, parameters).ConfigureAwait(false); } /// @@ -162,7 +162,7 @@ public void Refresh() public async Task RefreshAsync() { // driver.SwitchTo().DefaultContent(); - await this.driver.InternalExecuteAsync(DriverCommand.Refresh, null).ConfigureAwait(false); + await this.driver.ExecuteAsync(DriverCommand.Refresh, null).ConfigureAwait(false); } } } diff --git a/dotnet/src/webdriver/ShadowRoot.cs b/dotnet/src/webdriver/ShadowRoot.cs index a872d4fbc7d74..ef421a4b43bfb 100644 --- a/dotnet/src/webdriver/ShadowRoot.cs +++ b/dotnet/src/webdriver/ShadowRoot.cs @@ -98,7 +98,7 @@ public IWebElement FindElement(By by) parameters.Add("using", by.Mechanism); parameters.Add("value", by.Criteria); - Response commandResponse = this.driver.InternalExecute(DriverCommand.FindShadowChildElement, parameters); + Response commandResponse = this.driver.Execute(DriverCommand.FindShadowChildElement, parameters); return this.driver.GetElementFromResponse(commandResponse); } @@ -122,7 +122,7 @@ public ReadOnlyCollection FindElements(By by) parameters.Add("using", by.Mechanism); parameters.Add("value", by.Criteria); - Response commandResponse = this.driver.InternalExecute(DriverCommand.FindShadowChildElements, parameters); + Response commandResponse = this.driver.Execute(DriverCommand.FindShadowChildElements, parameters); return this.driver.GetElementsFromResponse(commandResponse); } diff --git a/dotnet/src/webdriver/TargetLocator.cs b/dotnet/src/webdriver/TargetLocator.cs index d8d57d933dcda..1b21eb6db0693 100644 --- a/dotnet/src/webdriver/TargetLocator.cs +++ b/dotnet/src/webdriver/TargetLocator.cs @@ -53,7 +53,7 @@ public IWebDriver Frame(int frameIndex) { Dictionary parameters = new Dictionary(); parameters.Add("id", frameIndex); - this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters); + this.driver.Execute(DriverCommand.SwitchToFrame, parameters); return this.driver; } @@ -116,7 +116,7 @@ public IWebDriver Frame(IWebElement frameElement) Dictionary parameters = new Dictionary(); parameters.Add("id", elementDictionary); - this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters); + this.driver.Execute(DriverCommand.SwitchToFrame, parameters); return this.driver; } @@ -127,7 +127,7 @@ public IWebDriver Frame(IWebElement frameElement) public IWebDriver ParentFrame() { Dictionary parameters = new Dictionary(); - this.driver.InternalExecute(DriverCommand.SwitchToParentFrame, parameters); + this.driver.Execute(DriverCommand.SwitchToParentFrame, parameters); return this.driver; } @@ -148,7 +148,7 @@ public IWebDriver Window(string windowHandleOrName) parameters.Add("handle", windowHandleOrName); try { - this.driver.InternalExecute(DriverCommand.SwitchToWindow, parameters); + this.driver.Execute(DriverCommand.SwitchToWindow, parameters); return this.driver; } catch (NoSuchWindowException) @@ -195,7 +195,7 @@ public IWebDriver NewWindow(WindowType typeHint) Dictionary parameters = new Dictionary(); parameters.Add("type", typeHint.ToString().ToLowerInvariant()); - Response response = this.driver.InternalExecute(DriverCommand.NewWindow, parameters); + Response response = this.driver.Execute(DriverCommand.NewWindow, parameters); Dictionary result = (Dictionary)response.Value!; string newWindowHandle = result["handle"].ToString()!; @@ -212,7 +212,7 @@ public IWebDriver DefaultContent() { Dictionary parameters = new Dictionary(); parameters.Add("id", null); - this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters); + this.driver.Execute(DriverCommand.SwitchToFrame, parameters); return this.driver; } @@ -222,7 +222,7 @@ public IWebDriver DefaultContent() /// Element that is active public IWebElement ActiveElement() { - Response response = this.driver.InternalExecute(DriverCommand.GetActiveElement, null); + Response response = this.driver.Execute(DriverCommand.GetActiveElement, null); return this.driver.GetElementFromResponse(response); } @@ -234,7 +234,7 @@ public IAlert Alert() { // N.B. We only execute the GetAlertText command to be able to throw // a NoAlertPresentException if there is no alert found. - this.driver.InternalExecute(DriverCommand.GetAlertText, null); + this.driver.Execute(DriverCommand.GetAlertText, null); return new Alert(this.driver); } } diff --git a/dotnet/src/webdriver/Timeouts.cs b/dotnet/src/webdriver/Timeouts.cs index b0f5882a7642d..ce9bf2c036e58 100644 --- a/dotnet/src/webdriver/Timeouts.cs +++ b/dotnet/src/webdriver/Timeouts.cs @@ -111,7 +111,7 @@ public TimeSpan PageLoad private TimeSpan ExecuteGetTimeout(string timeoutType) { - Response commandResponse = this.driver.InternalExecute(DriverCommand.GetTimeouts, null); + Response commandResponse = this.driver.Execute(DriverCommand.GetTimeouts, null); Dictionary responseValue = (Dictionary)commandResponse.Value!; if (!responseValue.TryGetValue(timeoutType, out object? timeout)) @@ -144,7 +144,7 @@ private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait) Dictionary parameters = new Dictionary(); parameters.Add(timeoutType, Convert.ToInt64(milliseconds)); - this.driver.InternalExecute(DriverCommand.SetTimeouts, parameters); + this.driver.Execute(DriverCommand.SetTimeouts, parameters); } } } diff --git a/dotnet/src/webdriver/WebDriver.cs b/dotnet/src/webdriver/WebDriver.cs index b5e8d5b6437b5..c7c4efe321005 100644 --- a/dotnet/src/webdriver/WebDriver.cs +++ b/dotnet/src/webdriver/WebDriver.cs @@ -576,36 +576,13 @@ internal ReadOnlyCollection GetElementsFromResponse(Response respon return toReturn.AsReadOnly(); } - /// - /// Executes commands with the driver - /// - /// Command that needs executing - /// Parameters needed for the command - /// WebDriver Response - internal Response InternalExecute(string driverCommandToExecute, Dictionary parameters) - { - return Task.Run(() => this.InternalExecuteAsync(driverCommandToExecute, parameters)).GetAwaiter().GetResult(); - } - - /// - /// Executes commands with the driver asynchronously - /// - /// Command that needs executing - /// Parameters needed for the command - /// A task object representing the asynchronous operation - internal Task InternalExecuteAsync(string driverCommandToExecute, - Dictionary parameters) - { - return this.ExecuteAsync(driverCommandToExecute, parameters); - } - /// /// Executes a command with this driver. /// /// A value representing the command to execute. /// A containing the names and values of the parameters of the command. /// A containing information about the success or failure of the command and any data returned by the command. - protected virtual Response Execute(string driverCommandToExecute, + protected internal virtual Response Execute(string driverCommandToExecute, Dictionary parameters) { return Task.Run(() => this.ExecuteAsync(driverCommandToExecute, parameters)).GetAwaiter().GetResult(); @@ -617,7 +594,7 @@ protected virtual Response Execute(string driverCommandToExecute, /// A value representing the command to execute. /// A containing the names and values of the parameters of the command. /// A containing information about the success or failure of the command and any data returned by the command. - protected virtual async Task ExecuteAsync(string driverCommandToExecute, Dictionary parameters) + protected internal virtual async Task ExecuteAsync(string driverCommandToExecute, Dictionary parameters) { Command commandToExecute = new Command(SessionId, driverCommandToExecute, parameters); diff --git a/dotnet/src/webdriver/WebElement.cs b/dotnet/src/webdriver/WebElement.cs index 0c0eca538b109..f36402bdf594d 100644 --- a/dotnet/src/webdriver/WebElement.cs +++ b/dotnet/src/webdriver/WebElement.cs @@ -684,7 +684,7 @@ Dictionary IWebDriverObjectReference.ToDictionary() /// The object containing the result of the command execution. protected virtual Response Execute(string commandToExecute, Dictionary parameters) { - return this.driver.InternalExecute(commandToExecute, parameters); + return this.driver.Execute(commandToExecute, parameters); } private static string GetAtom(string atomResourceName) diff --git a/dotnet/src/webdriver/Window.cs b/dotnet/src/webdriver/Window.cs index c856306bb668b..8aed90c635373 100644 --- a/dotnet/src/webdriver/Window.cs +++ b/dotnet/src/webdriver/Window.cs @@ -50,7 +50,7 @@ public Point Position { get { - Response commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null); + Response commandResponse = this.driver.Execute(DriverCommand.GetWindowRect, null); Dictionary rawPosition = (Dictionary)commandResponse.Value!; int x = Convert.ToInt32(rawPosition["x"], CultureInfo.InvariantCulture); @@ -64,7 +64,7 @@ public Point Position Dictionary parameters = new Dictionary(); parameters.Add("x", value.X); parameters.Add("y", value.Y); - this.driver.InternalExecute(DriverCommand.SetWindowRect, parameters); + this.driver.Execute(DriverCommand.SetWindowRect, parameters); } } @@ -76,7 +76,7 @@ public Size Size { get { - Response commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null); + Response commandResponse = this.driver.Execute(DriverCommand.GetWindowRect, null); Dictionary rawPosition = (Dictionary)commandResponse.Value!; int height = Convert.ToInt32(rawPosition["height"], CultureInfo.InvariantCulture); @@ -90,7 +90,7 @@ public Size Size Dictionary parameters = new Dictionary(); parameters.Add("width", value.Width); parameters.Add("height", value.Height); - this.driver.InternalExecute(DriverCommand.SetWindowRect, parameters); + this.driver.Execute(DriverCommand.SetWindowRect, parameters); } } @@ -99,7 +99,7 @@ public Size Size /// public void Maximize() { - this.driver.InternalExecute(DriverCommand.MaximizeWindow, null); + this.driver.Execute(DriverCommand.MaximizeWindow, null); } /// @@ -107,7 +107,7 @@ public void Maximize() /// public void Minimize() { - this.driver.InternalExecute(DriverCommand.MinimizeWindow, null); + this.driver.Execute(DriverCommand.MinimizeWindow, null); } /// @@ -115,7 +115,7 @@ public void Minimize() /// public void FullScreen() { - this.driver.InternalExecute(DriverCommand.FullScreenWindow, null); + this.driver.Execute(DriverCommand.FullScreenWindow, null); } } } From fab401a9fa45041df2989d85ece0d2bec1833e2b Mon Sep 17 00:00:00 2001 From: Michael Render Date: Mon, 31 Mar 2025 10:52:29 -0400 Subject: [PATCH 2/2] Fix merge issue --- dotnet/src/webdriver/WebDriver.cs | 32 ------------------------------- 1 file changed, 32 deletions(-) diff --git a/dotnet/src/webdriver/WebDriver.cs b/dotnet/src/webdriver/WebDriver.cs index 84b970729ab0a..4008ec1e15b66 100644 --- a/dotnet/src/webdriver/WebDriver.cs +++ b/dotnet/src/webdriver/WebDriver.cs @@ -551,38 +551,6 @@ internal ReadOnlyCollection GetElementsFromResponse(Response respon return toReturn.AsReadOnly(); } - /// - /// Executes commands with the driver - /// - /// Command that needs executing - /// Parameters needed for the command - /// WebDriver Response - /// If is . - internal Response InternalExecute(string driverCommandToExecute, Dictionary? parameters) - { - return Task.Run(() => this.InternalExecuteAsync(driverCommandToExecute, parameters)).GetAwaiter().GetResult(); - } - - /// - /// Executes commands with the driver asynchronously - /// - /// Command that needs executing - /// Parameters needed for the command - /// A task object representing the asynchronous operation - /// If is . - internal Task InternalExecuteAsync(string driverCommandToExecute, Dictionary? parameters) - { - return this.ExecuteAsync(driverCommandToExecute, parameters); - } - /// /// Executes a command with this driver. ///