Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Unify protected and internal Execute methods #15233

Merged
merged 4 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dotnet/src/webdriver/Alert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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;
}
}
Expand All @@ -55,15 +55,15 @@ public string? Text
/// </summary>
public void Dismiss()
{
this.driver.InternalExecute(DriverCommand.DismissAlert, null);
this.driver.Execute(DriverCommand.DismissAlert, null);
}

/// <summary>
/// Accepts the alert.
/// </summary>
public void Accept()
{
this.driver.InternalExecute(DriverCommand.AcceptAlert, null);
this.driver.Execute(DriverCommand.AcceptAlert, null);
}

/// <summary>
Expand All @@ -81,7 +81,7 @@ public void SendKeys(string keysToSend)
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("text", keysToSend);

this.driver.InternalExecute(DriverCommand.SetAlertValue, parameters);
this.driver.Execute(DriverCommand.SetAlertValue, parameters);
}
}
}
10 changes: 5 additions & 5 deletions dotnet/src/webdriver/CookieJar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ReadOnlyCollection<Cookie> AllCookies
{
get
{
Response response = driver.InternalExecute(DriverCommand.GetAllCookies, new Dictionary<string, object>());
Response response = driver.Execute(DriverCommand.GetAllCookies, new Dictionary<string, object>());

List<Cookie> toReturn = new List<Cookie>();
if (response.Value is object?[] cookies)
Expand Down Expand Up @@ -65,7 +65,7 @@ public void AddCookie(Cookie cookie)

Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("cookie", cookie);
driver.InternalExecute(DriverCommand.AddCookie, parameters);
driver.Execute(DriverCommand.AddCookie, parameters);
}

/// <summary>
Expand All @@ -82,7 +82,7 @@ public void DeleteCookieNamed(string name)

Dictionary<string, object> parameters = new() { { "name", name } };

driver.InternalExecute(DriverCommand.DeleteCookie, parameters);
driver.Execute(DriverCommand.DeleteCookie, parameters);
}

/// <summary>
Expand All @@ -105,7 +105,7 @@ public void DeleteCookie(Cookie cookie)
/// </summary>
public void DeleteAllCookies()
{
driver.InternalExecute(DriverCommand.DeleteAllCookies, null);
driver.Execute(DriverCommand.DeleteAllCookies, null);
}

/// <summary>
Expand All @@ -123,7 +123,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<string, object?>)rawCookie!);
}
Expand Down
5 changes: 3 additions & 2 deletions dotnet/src/webdriver/HttpCommandInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ public class HttpCommandInfo : CommandInfo
/// </summary>
/// <param name="method">Method of the Command</param>
/// <param name="resourcePath">Relative URL path to the resource used to execute the command</param>
/// <exception cref="ArgumentNullException">If <paramref name="method"/> or <paramref name="resourcePath"/> are <see langword="null"/>.</exception>
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));
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/webdriver/Logs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ReadOnlyCollection<string> AvailableLogTypes
List<string> availableLogTypes = new List<string>();
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)
Expand Down Expand Up @@ -86,7 +86,7 @@ public ReadOnlyCollection<LogEntry> GetLog(string logKind)

Dictionary<string, object> parameters = new Dictionary<string, object>();
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)
{
Expand Down
8 changes: 4 additions & 4 deletions dotnet/src/webdriver/Navigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void Back()
/// <returns>A task object representing the asynchronous operation.</returns>
public async Task BackAsync()
{
await this.driver.InternalExecuteAsync(DriverCommand.GoBack, null).ConfigureAwait(false);
await this.driver.ExecuteAsync(DriverCommand.GoBack, null).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -77,7 +77,7 @@ public void Forward()
/// <returns>A task object representing the asynchronous operation.</returns>
public async Task ForwardAsync()
{
await this.driver.InternalExecuteAsync(DriverCommand.GoForward, null).ConfigureAwait(false);
await this.driver.ExecuteAsync(DriverCommand.GoForward, null).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -110,7 +110,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);
}

/// <summary>
Expand Down Expand Up @@ -160,7 +160,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);
}
}
}
4 changes: 2 additions & 2 deletions dotnet/src/webdriver/ShadowRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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)!;
}

Expand All @@ -120,7 +120,7 @@ public ReadOnlyCollection<IWebElement> 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);
}

Expand Down
16 changes: 8 additions & 8 deletions dotnet/src/webdriver/TargetLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public IWebDriver Frame(int frameIndex)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("id", frameIndex);
this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters);
this.driver.Execute(DriverCommand.SwitchToFrame, parameters);
return this.driver;
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public IWebDriver Frame(IWebElement frameElement)

Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("id", elementDictionary);
this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters);
this.driver.Execute(DriverCommand.SwitchToFrame, parameters);
return this.driver;
}

Expand All @@ -125,7 +125,7 @@ public IWebDriver Frame(IWebElement frameElement)
public IWebDriver ParentFrame()
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
this.driver.InternalExecute(DriverCommand.SwitchToParentFrame, parameters);
this.driver.Execute(DriverCommand.SwitchToParentFrame, parameters);
return this.driver;
}

Expand All @@ -146,7 +146,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)
Expand Down Expand Up @@ -193,7 +193,7 @@ public IWebDriver NewWindow(WindowType typeHint)
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("type", typeHint.ToString().ToLowerInvariant());

Response response = this.driver.InternalExecute(DriverCommand.NewWindow, parameters);
Response response = this.driver.Execute(DriverCommand.NewWindow, parameters);

Dictionary<string, object> result = (Dictionary<string, object>)response.Value!;
string newWindowHandle = result["handle"].ToString()!;
Expand All @@ -210,7 +210,7 @@ public IWebDriver DefaultContent()
{
Dictionary<string, object?> parameters = new Dictionary<string, object?>();
parameters.Add("id", null);
this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters);
this.driver.Execute(DriverCommand.SwitchToFrame, parameters);
return this.driver;
}

Expand All @@ -220,7 +220,7 @@ public IWebDriver DefaultContent()
/// <returns>Element that is active</returns>
public IWebElement ActiveElement()
{
Response response = this.driver.InternalExecute(DriverCommand.GetActiveElement, null);
Response response = this.driver.Execute(DriverCommand.GetActiveElement, null);
return this.driver.GetElementFromResponse(response)!;
}

Expand All @@ -232,7 +232,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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/webdriver/Timeouts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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<string, object?> responseValue = (Dictionary<string, object?>)commandResponse.Value!;
if (!responseValue.TryGetValue(timeoutType, out object? timeout))
Expand Down Expand Up @@ -142,7 +142,7 @@ private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait)
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add(timeoutType, Convert.ToInt64(milliseconds));

this.driver.InternalExecute(DriverCommand.SetTimeouts, parameters);
this.driver.Execute(DriverCommand.SetTimeouts, parameters);
}
}
}
36 changes: 2 additions & 34 deletions dotnet/src/webdriver/WebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,46 +551,14 @@ internal ReadOnlyCollection<IWebElement> GetElementsFromResponse(Response respon
return toReturn.AsReadOnly();
}

/// <summary>
/// Executes commands with the driver
/// </summary>
/// <param name="driverCommandToExecute">Command that needs executing</param>
/// <param name="parameters">Parameters needed for the command</param>
/// <returns>WebDriver Response</returns>
/// <exception cref="ArgumentNullException">If <paramref name="driverCommandToExecute"/> is <see langword="null"/>.</exception>
internal Response InternalExecute(string driverCommandToExecute, Dictionary<string,
#nullable disable
object
#nullable enable
>? parameters)
{
return Task.Run(() => this.InternalExecuteAsync(driverCommandToExecute, parameters)).GetAwaiter().GetResult();
}

/// <summary>
/// Executes commands with the driver asynchronously
/// </summary>
/// <param name="driverCommandToExecute">Command that needs executing</param>
/// <param name="parameters">Parameters needed for the command</param>
/// <returns>A task object representing the asynchronous operation</returns>
/// <exception cref="ArgumentNullException">If <paramref name="driverCommandToExecute"/> is <see langword="null"/>.</exception>
internal Task<Response> InternalExecuteAsync(string driverCommandToExecute, Dictionary<string,
#nullable disable
object
#nullable enable
>? parameters)
{
return this.ExecuteAsync(driverCommandToExecute, parameters);
}

/// <summary>
/// Executes a command with this driver.
/// </summary>
/// <param name="driverCommandToExecute">A <see cref="DriverCommand"/> value representing the command to execute.</param>
/// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing the names and values of the parameters of the command.</param>
/// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="driverCommandToExecute"/> is <see langword="null"/>.</exception>
protected virtual Response Execute(string driverCommandToExecute, Dictionary<string,
protected internal virtual Response Execute(string driverCommandToExecute, Dictionary<string,
#nullable disable
object
#nullable enable
Expand All @@ -606,7 +574,7 @@ protected virtual Response Execute(string driverCommandToExecute, Dictionary<str
/// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing the names and values of the parameters of the command.</param>
/// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="driverCommandToExecute"/> is <see langword="null"/>.</exception>
protected virtual async Task<Response> ExecuteAsync(string driverCommandToExecute, Dictionary<string,
protected internal virtual async Task<Response> ExecuteAsync(string driverCommandToExecute, Dictionary<string,
#nullable disable
object
#nullable enable
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/WebElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ protected virtual Response Execute(string commandToExecute, Dictionary<string,
#nullable enable
>? parameters)
{
return this.driver.InternalExecute(commandToExecute, parameters);
return this.driver.Execute(commandToExecute, parameters);
}

private static string GetAtom(string atomResourceName)
Expand Down
14 changes: 7 additions & 7 deletions dotnet/src/webdriver/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Point Position
{
get
{
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null);
Response commandResponse = this.driver.Execute(DriverCommand.GetWindowRect, null);

Dictionary<string, object?> rawPosition = (Dictionary<string, object?>)commandResponse.Value!;
int x = Convert.ToInt32(rawPosition["x"], CultureInfo.InvariantCulture);
Expand All @@ -62,7 +62,7 @@ public Point Position
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("x", value.X);
parameters.Add("y", value.Y);
this.driver.InternalExecute(DriverCommand.SetWindowRect, parameters);
this.driver.Execute(DriverCommand.SetWindowRect, parameters);
}
}

Expand All @@ -74,7 +74,7 @@ public Size Size
{
get
{
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null);
Response commandResponse = this.driver.Execute(DriverCommand.GetWindowRect, null);

Dictionary<string, object?> rawPosition = (Dictionary<string, object?>)commandResponse.Value!;
int height = Convert.ToInt32(rawPosition["height"], CultureInfo.InvariantCulture);
Expand All @@ -88,7 +88,7 @@ public Size Size
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("width", value.Width);
parameters.Add("height", value.Height);
this.driver.InternalExecute(DriverCommand.SetWindowRect, parameters);
this.driver.Execute(DriverCommand.SetWindowRect, parameters);
}
}

Expand All @@ -97,23 +97,23 @@ public Size Size
/// </summary>
public void Maximize()
{
this.driver.InternalExecute(DriverCommand.MaximizeWindow, null);
this.driver.Execute(DriverCommand.MaximizeWindow, null);
}

/// <summary>
/// Minimizes the current window if it is not already minimized.
/// </summary>
public void Minimize()
{
this.driver.InternalExecute(DriverCommand.MinimizeWindow, null);
this.driver.Execute(DriverCommand.MinimizeWindow, null);
}

/// <summary>
/// Sets the current window to full screen if it is not already in that state.
/// </summary>
public void FullScreen()
{
this.driver.InternalExecute(DriverCommand.FullScreenWindow, null);
this.driver.Execute(DriverCommand.FullScreenWindow, null);
}
}
}
Loading