Skip to content

Commit ee17b37

Browse files
[dotnet] Unify protected and internal Execute methods (#15233)
* [dotnet] Unify protected and internal Execute methods * Fix merge issue
1 parent 75615d5 commit ee17b37

11 files changed

+40
-71
lines changed

dotnet/src/webdriver/Alert.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public string? Text
4545
{
4646
get
4747
{
48-
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetAlertText, null);
48+
Response commandResponse = this.driver.Execute(DriverCommand.GetAlertText, null);
4949
return (string?)commandResponse.Value;
5050
}
5151
}
@@ -55,15 +55,15 @@ public string? Text
5555
/// </summary>
5656
public void Dismiss()
5757
{
58-
this.driver.InternalExecute(DriverCommand.DismissAlert, null);
58+
this.driver.Execute(DriverCommand.DismissAlert, null);
5959
}
6060

6161
/// <summary>
6262
/// Accepts the alert.
6363
/// </summary>
6464
public void Accept()
6565
{
66-
this.driver.InternalExecute(DriverCommand.AcceptAlert, null);
66+
this.driver.Execute(DriverCommand.AcceptAlert, null);
6767
}
6868

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

84-
this.driver.InternalExecute(DriverCommand.SetAlertValue, parameters);
84+
this.driver.Execute(DriverCommand.SetAlertValue, parameters);
8585
}
8686
}
8787
}

dotnet/src/webdriver/CookieJar.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public ReadOnlyCollection<Cookie> AllCookies
3232
{
3333
get
3434
{
35-
Response response = driver.InternalExecute(DriverCommand.GetAllCookies, new Dictionary<string, object>());
35+
Response response = driver.Execute(DriverCommand.GetAllCookies, new Dictionary<string, object>());
3636

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

6666
Dictionary<string, object> parameters = new Dictionary<string, object>();
6767
parameters.Add("cookie", cookie);
68-
driver.InternalExecute(DriverCommand.AddCookie, parameters);
68+
driver.Execute(DriverCommand.AddCookie, parameters);
6969
}
7070

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

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

85-
driver.InternalExecute(DriverCommand.DeleteCookie, parameters);
85+
driver.Execute(DriverCommand.DeleteCookie, parameters);
8686
}
8787

8888
/// <summary>
@@ -105,7 +105,7 @@ public void DeleteCookie(Cookie cookie)
105105
/// </summary>
106106
public void DeleteAllCookies()
107107
{
108-
driver.InternalExecute(DriverCommand.DeleteAllCookies, null);
108+
driver.Execute(DriverCommand.DeleteAllCookies, null);
109109
}
110110

111111
/// <summary>
@@ -123,7 +123,7 @@ public void DeleteAllCookies()
123123

124124
try
125125
{
126-
var rawCookie = driver.InternalExecute(DriverCommand.GetCookie, new() { { "name", name } }).Value;
126+
var rawCookie = driver.Execute(DriverCommand.GetCookie, new() { { "name", name } }).Value;
127127

128128
return Cookie.FromDictionary((Dictionary<string, object?>)rawCookie!);
129129
}

dotnet/src/webdriver/HttpCommandInfo.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ public class HttpCommandInfo : CommandInfo
4949
/// </summary>
5050
/// <param name="method">Method of the Command</param>
5151
/// <param name="resourcePath">Relative URL path to the resource used to execute the command</param>
52+
/// <exception cref="ArgumentNullException">If <paramref name="method"/> or <paramref name="resourcePath"/> are <see langword="null"/>.</exception>
5253
public HttpCommandInfo(string method, string resourcePath)
5354
{
54-
this.ResourcePath = resourcePath;
55-
this.Method = method;
55+
this.ResourcePath = resourcePath ?? throw new ArgumentNullException(nameof(resourcePath));
56+
this.Method = method ?? throw new ArgumentNullException(nameof(method));
5657
}
5758

5859
/// <summary>

dotnet/src/webdriver/Logs.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public ReadOnlyCollection<string> AvailableLogTypes
5050
List<string> availableLogTypes = new List<string>();
5151
try
5252
{
53-
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetAvailableLogTypes, null);
53+
Response commandResponse = this.driver.Execute(DriverCommand.GetAvailableLogTypes, null);
5454
if (commandResponse.Value is object[] responseValue)
5555
{
5656
foreach (object logKind in responseValue)
@@ -86,7 +86,7 @@ public ReadOnlyCollection<LogEntry> GetLog(string logKind)
8686

8787
Dictionary<string, object> parameters = new Dictionary<string, object>();
8888
parameters.Add("type", logKind);
89-
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetLog, parameters);
89+
Response commandResponse = this.driver.Execute(DriverCommand.GetLog, parameters);
9090

9191
if (commandResponse.Value is object?[] responseValue)
9292
{

dotnet/src/webdriver/Navigator.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void Back()
5757
/// <returns>A task object representing the asynchronous operation.</returns>
5858
public async Task BackAsync()
5959
{
60-
await this.driver.InternalExecuteAsync(DriverCommand.GoBack, null).ConfigureAwait(false);
60+
await this.driver.ExecuteAsync(DriverCommand.GoBack, null).ConfigureAwait(false);
6161
}
6262

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

8383
/// <summary>
@@ -110,7 +110,7 @@ public async Task GoToUrlAsync(string url)
110110
{
111111
{ "url", url }
112112
};
113-
await this.driver.InternalExecuteAsync(DriverCommand.Get, parameters).ConfigureAwait(false);
113+
await this.driver.ExecuteAsync(DriverCommand.Get, parameters).ConfigureAwait(false);
114114
}
115115

116116
/// <summary>
@@ -160,7 +160,7 @@ public void Refresh()
160160
public async Task RefreshAsync()
161161
{
162162
// driver.SwitchTo().DefaultContent();
163-
await this.driver.InternalExecuteAsync(DriverCommand.Refresh, null).ConfigureAwait(false);
163+
await this.driver.ExecuteAsync(DriverCommand.Refresh, null).ConfigureAwait(false);
164164
}
165165
}
166166
}

dotnet/src/webdriver/ShadowRoot.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public IWebElement FindElement(By by)
9696
parameters.Add("using", by.Mechanism);
9797
parameters.Add("value", by.Criteria);
9898

99-
Response commandResponse = this.driver.InternalExecute(DriverCommand.FindShadowChildElement, parameters);
99+
Response commandResponse = this.driver.Execute(DriverCommand.FindShadowChildElement, parameters);
100100
return this.driver.GetElementFromResponse(commandResponse)!;
101101
}
102102

@@ -120,7 +120,7 @@ public ReadOnlyCollection<IWebElement> FindElements(By by)
120120
parameters.Add("using", by.Mechanism);
121121
parameters.Add("value", by.Criteria);
122122

123-
Response commandResponse = this.driver.InternalExecute(DriverCommand.FindShadowChildElements, parameters);
123+
Response commandResponse = this.driver.Execute(DriverCommand.FindShadowChildElements, parameters);
124124
return this.driver.GetElementsFromResponse(commandResponse);
125125
}
126126

dotnet/src/webdriver/TargetLocator.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public IWebDriver Frame(int frameIndex)
5151
{
5252
Dictionary<string, object> parameters = new Dictionary<string, object>();
5353
parameters.Add("id", frameIndex);
54-
this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters);
54+
this.driver.Execute(DriverCommand.SwitchToFrame, parameters);
5555
return this.driver;
5656
}
5757

@@ -114,7 +114,7 @@ public IWebDriver Frame(IWebElement frameElement)
114114

115115
Dictionary<string, object> parameters = new Dictionary<string, object>();
116116
parameters.Add("id", elementDictionary);
117-
this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters);
117+
this.driver.Execute(DriverCommand.SwitchToFrame, parameters);
118118
return this.driver;
119119
}
120120

@@ -125,7 +125,7 @@ public IWebDriver Frame(IWebElement frameElement)
125125
public IWebDriver ParentFrame()
126126
{
127127
Dictionary<string, object> parameters = new Dictionary<string, object>();
128-
this.driver.InternalExecute(DriverCommand.SwitchToParentFrame, parameters);
128+
this.driver.Execute(DriverCommand.SwitchToParentFrame, parameters);
129129
return this.driver;
130130
}
131131

@@ -146,7 +146,7 @@ public IWebDriver Window(string windowHandleOrName)
146146
parameters.Add("handle", windowHandleOrName);
147147
try
148148
{
149-
this.driver.InternalExecute(DriverCommand.SwitchToWindow, parameters);
149+
this.driver.Execute(DriverCommand.SwitchToWindow, parameters);
150150
return this.driver;
151151
}
152152
catch (NoSuchWindowException)
@@ -193,7 +193,7 @@ public IWebDriver NewWindow(WindowType typeHint)
193193
Dictionary<string, object> parameters = new Dictionary<string, object>();
194194
parameters.Add("type", typeHint.ToString().ToLowerInvariant());
195195

196-
Response response = this.driver.InternalExecute(DriverCommand.NewWindow, parameters);
196+
Response response = this.driver.Execute(DriverCommand.NewWindow, parameters);
197197

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

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

@@ -232,7 +232,7 @@ public IAlert Alert()
232232
{
233233
// N.B. We only execute the GetAlertText command to be able to throw
234234
// a NoAlertPresentException if there is no alert found.
235-
this.driver.InternalExecute(DriverCommand.GetAlertText, null);
235+
this.driver.Execute(DriverCommand.GetAlertText, null);
236236
return new Alert(this.driver);
237237
}
238238
}

dotnet/src/webdriver/Timeouts.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public TimeSpan PageLoad
109109

110110
private TimeSpan ExecuteGetTimeout(string timeoutType)
111111
{
112-
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetTimeouts, null);
112+
Response commandResponse = this.driver.Execute(DriverCommand.GetTimeouts, null);
113113

114114
Dictionary<string, object?> responseValue = (Dictionary<string, object?>)commandResponse.Value!;
115115
if (!responseValue.TryGetValue(timeoutType, out object? timeout))
@@ -142,7 +142,7 @@ private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait)
142142
Dictionary<string, object> parameters = new Dictionary<string, object>();
143143
parameters.Add(timeoutType, Convert.ToInt64(milliseconds));
144144

145-
this.driver.InternalExecute(DriverCommand.SetTimeouts, parameters);
145+
this.driver.Execute(DriverCommand.SetTimeouts, parameters);
146146
}
147147
}
148148
}

dotnet/src/webdriver/WebDriver.cs

+2-34
Original file line numberDiff line numberDiff line change
@@ -551,46 +551,14 @@ internal ReadOnlyCollection<IWebElement> GetElementsFromResponse(Response respon
551551
return toReturn.AsReadOnly();
552552
}
553553

554-
/// <summary>
555-
/// Executes commands with the driver
556-
/// </summary>
557-
/// <param name="driverCommandToExecute">Command that needs executing</param>
558-
/// <param name="parameters">Parameters needed for the command</param>
559-
/// <returns>WebDriver Response</returns>
560-
/// <exception cref="ArgumentNullException">If <paramref name="driverCommandToExecute"/> is <see langword="null"/>.</exception>
561-
internal Response InternalExecute(string driverCommandToExecute, Dictionary<string,
562-
#nullable disable
563-
object
564-
#nullable enable
565-
>? parameters)
566-
{
567-
return Task.Run(() => this.InternalExecuteAsync(driverCommandToExecute, parameters)).GetAwaiter().GetResult();
568-
}
569-
570-
/// <summary>
571-
/// Executes commands with the driver asynchronously
572-
/// </summary>
573-
/// <param name="driverCommandToExecute">Command that needs executing</param>
574-
/// <param name="parameters">Parameters needed for the command</param>
575-
/// <returns>A task object representing the asynchronous operation</returns>
576-
/// <exception cref="ArgumentNullException">If <paramref name="driverCommandToExecute"/> is <see langword="null"/>.</exception>
577-
internal Task<Response> InternalExecuteAsync(string driverCommandToExecute, Dictionary<string,
578-
#nullable disable
579-
object
580-
#nullable enable
581-
>? parameters)
582-
{
583-
return this.ExecuteAsync(driverCommandToExecute, parameters);
584-
}
585-
586554
/// <summary>
587555
/// Executes a command with this driver.
588556
/// </summary>
589557
/// <param name="driverCommandToExecute">A <see cref="DriverCommand"/> value representing the command to execute.</param>
590558
/// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing the names and values of the parameters of the command.</param>
591559
/// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns>
592560
/// <exception cref="ArgumentNullException">If <paramref name="driverCommandToExecute"/> is <see langword="null"/>.</exception>
593-
protected virtual Response Execute(string driverCommandToExecute, Dictionary<string,
561+
protected internal virtual Response Execute(string driverCommandToExecute, Dictionary<string,
594562
#nullable disable
595563
object
596564
#nullable enable
@@ -606,7 +574,7 @@ protected virtual Response Execute(string driverCommandToExecute, Dictionary<str
606574
/// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing the names and values of the parameters of the command.</param>
607575
/// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns>
608576
/// <exception cref="ArgumentNullException">If <paramref name="driverCommandToExecute"/> is <see langword="null"/>.</exception>
609-
protected virtual async Task<Response> ExecuteAsync(string driverCommandToExecute, Dictionary<string,
577+
protected internal virtual async Task<Response> ExecuteAsync(string driverCommandToExecute, Dictionary<string,
610578
#nullable disable
611579
object
612580
#nullable enable

dotnet/src/webdriver/WebElement.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ protected virtual Response Execute(string commandToExecute, Dictionary<string,
703703
#nullable enable
704704
>? parameters)
705705
{
706-
return this.driver.InternalExecute(commandToExecute, parameters);
706+
return this.driver.Execute(commandToExecute, parameters);
707707
}
708708

709709
private static string GetAtom(string atomResourceName)

dotnet/src/webdriver/Window.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public Point Position
4848
{
4949
get
5050
{
51-
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null);
51+
Response commandResponse = this.driver.Execute(DriverCommand.GetWindowRect, null);
5252

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

@@ -74,7 +74,7 @@ public Size Size
7474
{
7575
get
7676
{
77-
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null);
77+
Response commandResponse = this.driver.Execute(DriverCommand.GetWindowRect, null);
7878

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

@@ -97,23 +97,23 @@ public Size Size
9797
/// </summary>
9898
public void Maximize()
9999
{
100-
this.driver.InternalExecute(DriverCommand.MaximizeWindow, null);
100+
this.driver.Execute(DriverCommand.MaximizeWindow, null);
101101
}
102102

103103
/// <summary>
104104
/// Minimizes the current window if it is not already minimized.
105105
/// </summary>
106106
public void Minimize()
107107
{
108-
this.driver.InternalExecute(DriverCommand.MinimizeWindow, null);
108+
this.driver.Execute(DriverCommand.MinimizeWindow, null);
109109
}
110110

111111
/// <summary>
112112
/// Sets the current window to full screen if it is not already in that state.
113113
/// </summary>
114114
public void FullScreen()
115115
{
116-
this.driver.InternalExecute(DriverCommand.FullScreenWindow, null);
116+
this.driver.Execute(DriverCommand.FullScreenWindow, null);
117117
}
118118
}
119119
}

0 commit comments

Comments
 (0)