Skip to content

Commit e3aace6

Browse files
committed
[dotnet] Unify protected and internal Execute methods
1 parent 2357514 commit e3aace6

File tree

11 files changed

+40
-62
lines changed

11 files changed

+40
-62
lines changed

dotnet/src/webdriver/Alert.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public string? Text
4747
{
4848
get
4949
{
50-
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetAlertText, null);
50+
Response commandResponse = this.driver.Execute(DriverCommand.GetAlertText, null);
5151
return (string?)commandResponse.Value;
5252
}
5353
}
@@ -57,15 +57,15 @@ public string? Text
5757
/// </summary>
5858
public void Dismiss()
5959
{
60-
this.driver.InternalExecute(DriverCommand.DismissAlert, null);
60+
this.driver.Execute(DriverCommand.DismissAlert, null);
6161
}
6262

6363
/// <summary>
6464
/// Accepts the alert.
6565
/// </summary>
6666
public void Accept()
6767
{
68-
this.driver.InternalExecute(DriverCommand.AcceptAlert, null);
68+
this.driver.Execute(DriverCommand.AcceptAlert, null);
6969
}
7070

7171
/// <summary>
@@ -83,7 +83,7 @@ public void SendKeys(string keysToSend)
8383
Dictionary<string, object> parameters = new Dictionary<string, object>();
8484
parameters.Add("text", keysToSend);
8585

86-
this.driver.InternalExecute(DriverCommand.SetAlertValue, parameters);
86+
this.driver.Execute(DriverCommand.SetAlertValue, parameters);
8787
}
8888
}
8989
}

dotnet/src/webdriver/CookieJar.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public ReadOnlyCollection<Cookie> AllCookies
3434
{
3535
get
3636
{
37-
Response response = driver.InternalExecute(DriverCommand.GetAllCookies, new Dictionary<string, object>());
37+
Response response = driver.Execute(DriverCommand.GetAllCookies, new Dictionary<string, object>());
3838

3939
List<Cookie> toReturn = new List<Cookie>();
4040
if (response.Value is object?[] cookies)
@@ -67,7 +67,7 @@ public void AddCookie(Cookie cookie)
6767

6868
Dictionary<string, object> parameters = new Dictionary<string, object>();
6969
parameters.Add("cookie", cookie);
70-
driver.InternalExecute(DriverCommand.AddCookie, parameters);
70+
driver.Execute(DriverCommand.AddCookie, parameters);
7171
}
7272

7373
/// <summary>
@@ -84,7 +84,7 @@ public void DeleteCookieNamed(string name)
8484

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

87-
driver.InternalExecute(DriverCommand.DeleteCookie, parameters);
87+
driver.Execute(DriverCommand.DeleteCookie, parameters);
8888
}
8989

9090
/// <summary>
@@ -107,7 +107,7 @@ public void DeleteCookie(Cookie cookie)
107107
/// </summary>
108108
public void DeleteAllCookies()
109109
{
110-
driver.InternalExecute(DriverCommand.DeleteAllCookies, null);
110+
driver.Execute(DriverCommand.DeleteAllCookies, null);
111111
}
112112

113113
/// <summary>
@@ -125,7 +125,7 @@ public void DeleteAllCookies()
125125

126126
try
127127
{
128-
var rawCookie = driver.InternalExecute(DriverCommand.GetCookie, new() { { "name", name } }).Value;
128+
var rawCookie = driver.Execute(DriverCommand.GetCookie, new() { { "name", name } }).Value;
129129

130130
return Cookie.FromDictionary((Dictionary<string, object>)rawCookie!);
131131
}

dotnet/src/webdriver/HttpCommandInfo.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ public class HttpCommandInfo : CommandInfo
5151
/// </summary>
5252
/// <param name="method">Method of the Command</param>
5353
/// <param name="resourcePath">Relative URL path to the resource used to execute the command</param>
54+
/// <exception cref="ArgumentNullException">If <paramref name="method"/> or <paramref name="resourcePath"/> are <see langword="null"/>.</exception>
5455
public HttpCommandInfo(string method, string resourcePath)
5556
{
56-
this.ResourcePath = resourcePath;
57-
this.Method = method;
57+
this.ResourcePath = resourcePath ?? throw new ArgumentNullException(nameof(resourcePath));
58+
this.Method = method ?? throw new ArgumentNullException(nameof(method));
5859
}
5960

6061
/// <summary>

dotnet/src/webdriver/Logs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public ReadOnlyCollection<string> AvailableLogTypes
5252
List<string> availableLogTypes = new List<string>();
5353
try
5454
{
55-
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetAvailableLogTypes, null);
55+
Response commandResponse = this.driver.Execute(DriverCommand.GetAvailableLogTypes, null);
5656
if (commandResponse.Value is object[] responseValue)
5757
{
5858
foreach (object logKind in responseValue)
@@ -88,7 +88,7 @@ public ReadOnlyCollection<LogEntry> GetLog(string logKind)
8888

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

9393
if (commandResponse.Value is object?[] responseValue)
9494
{

dotnet/src/webdriver/Navigator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void Back()
5959
/// <returns>A task object representing the asynchronous operation.</returns>
6060
public async Task BackAsync()
6161
{
62-
await this.driver.InternalExecuteAsync(DriverCommand.GoBack, null).ConfigureAwait(false);
62+
await this.driver.ExecuteAsync(DriverCommand.GoBack, null).ConfigureAwait(false);
6363
}
6464

6565
/// <summary>
@@ -79,7 +79,7 @@ public void Forward()
7979
/// <returns>A task object representing the asynchronous operation.</returns>
8080
public async Task ForwardAsync()
8181
{
82-
await this.driver.InternalExecuteAsync(DriverCommand.GoForward, null).ConfigureAwait(false);
82+
await this.driver.ExecuteAsync(DriverCommand.GoForward, null).ConfigureAwait(false);
8383
}
8484

8585
/// <summary>
@@ -112,7 +112,7 @@ public async Task GoToUrlAsync(string url)
112112
{
113113
{ "url", url }
114114
};
115-
await this.driver.InternalExecuteAsync(DriverCommand.Get, parameters).ConfigureAwait(false);
115+
await this.driver.ExecuteAsync(DriverCommand.Get, parameters).ConfigureAwait(false);
116116
}
117117

118118
/// <summary>
@@ -162,7 +162,7 @@ public void Refresh()
162162
public async Task RefreshAsync()
163163
{
164164
// driver.SwitchTo().DefaultContent();
165-
await this.driver.InternalExecuteAsync(DriverCommand.Refresh, null).ConfigureAwait(false);
165+
await this.driver.ExecuteAsync(DriverCommand.Refresh, null).ConfigureAwait(false);
166166
}
167167
}
168168
}

dotnet/src/webdriver/ShadowRoot.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public IWebElement FindElement(By by)
9898
parameters.Add("using", by.Mechanism);
9999
parameters.Add("value", by.Criteria);
100100

101-
Response commandResponse = this.driver.InternalExecute(DriverCommand.FindShadowChildElement, parameters);
101+
Response commandResponse = this.driver.Execute(DriverCommand.FindShadowChildElement, parameters);
102102
return this.driver.GetElementFromResponse(commandResponse);
103103
}
104104

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

125-
Response commandResponse = this.driver.InternalExecute(DriverCommand.FindShadowChildElements, parameters);
125+
Response commandResponse = this.driver.Execute(DriverCommand.FindShadowChildElements, parameters);
126126
return this.driver.GetElementsFromResponse(commandResponse);
127127
}
128128

dotnet/src/webdriver/TargetLocator.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public IWebDriver Frame(int frameIndex)
5353
{
5454
Dictionary<string, object> parameters = new Dictionary<string, object>();
5555
parameters.Add("id", frameIndex);
56-
this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters);
56+
this.driver.Execute(DriverCommand.SwitchToFrame, parameters);
5757
return this.driver;
5858
}
5959

@@ -116,7 +116,7 @@ public IWebDriver Frame(IWebElement frameElement)
116116

117117
Dictionary<string, object> parameters = new Dictionary<string, object>();
118118
parameters.Add("id", elementDictionary);
119-
this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters);
119+
this.driver.Execute(DriverCommand.SwitchToFrame, parameters);
120120
return this.driver;
121121
}
122122

@@ -127,7 +127,7 @@ public IWebDriver Frame(IWebElement frameElement)
127127
public IWebDriver ParentFrame()
128128
{
129129
Dictionary<string, object> parameters = new Dictionary<string, object>();
130-
this.driver.InternalExecute(DriverCommand.SwitchToParentFrame, parameters);
130+
this.driver.Execute(DriverCommand.SwitchToParentFrame, parameters);
131131
return this.driver;
132132
}
133133

@@ -148,7 +148,7 @@ public IWebDriver Window(string windowHandleOrName)
148148
parameters.Add("handle", windowHandleOrName);
149149
try
150150
{
151-
this.driver.InternalExecute(DriverCommand.SwitchToWindow, parameters);
151+
this.driver.Execute(DriverCommand.SwitchToWindow, parameters);
152152
return this.driver;
153153
}
154154
catch (NoSuchWindowException)
@@ -195,7 +195,7 @@ public IWebDriver NewWindow(WindowType typeHint)
195195
Dictionary<string, object> parameters = new Dictionary<string, object>();
196196
parameters.Add("type", typeHint.ToString().ToLowerInvariant());
197197

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

200200
Dictionary<string, object> result = (Dictionary<string, object>)response.Value!;
201201
string newWindowHandle = result["handle"].ToString()!;
@@ -212,7 +212,7 @@ public IWebDriver DefaultContent()
212212
{
213213
Dictionary<string, object?> parameters = new Dictionary<string, object?>();
214214
parameters.Add("id", null);
215-
this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters);
215+
this.driver.Execute(DriverCommand.SwitchToFrame, parameters);
216216
return this.driver;
217217
}
218218

@@ -222,7 +222,7 @@ public IWebDriver DefaultContent()
222222
/// <returns>Element that is active</returns>
223223
public IWebElement ActiveElement()
224224
{
225-
Response response = this.driver.InternalExecute(DriverCommand.GetActiveElement, null);
225+
Response response = this.driver.Execute(DriverCommand.GetActiveElement, null);
226226
return this.driver.GetElementFromResponse(response);
227227
}
228228

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

dotnet/src/webdriver/Timeouts.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public TimeSpan PageLoad
111111

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

116116
Dictionary<string, object?> responseValue = (Dictionary<string, object?>)commandResponse.Value!;
117117
if (!responseValue.TryGetValue(timeoutType, out object? timeout))
@@ -144,7 +144,7 @@ private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait)
144144
Dictionary<string, object> parameters = new Dictionary<string, object>();
145145
parameters.Add(timeoutType, Convert.ToInt64(milliseconds));
146146

147-
this.driver.InternalExecute(DriverCommand.SetTimeouts, parameters);
147+
this.driver.Execute(DriverCommand.SetTimeouts, parameters);
148148
}
149149
}
150150
}

dotnet/src/webdriver/WebDriver.cs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -576,36 +576,13 @@ internal ReadOnlyCollection<IWebElement> GetElementsFromResponse(Response respon
576576
return toReturn.AsReadOnly();
577577
}
578578

579-
/// <summary>
580-
/// Executes commands with the driver
581-
/// </summary>
582-
/// <param name="driverCommandToExecute">Command that needs executing</param>
583-
/// <param name="parameters">Parameters needed for the command</param>
584-
/// <returns>WebDriver Response</returns>
585-
internal Response InternalExecute(string driverCommandToExecute, Dictionary<string, object> parameters)
586-
{
587-
return Task.Run(() => this.InternalExecuteAsync(driverCommandToExecute, parameters)).GetAwaiter().GetResult();
588-
}
589-
590-
/// <summary>
591-
/// Executes commands with the driver asynchronously
592-
/// </summary>
593-
/// <param name="driverCommandToExecute">Command that needs executing</param>
594-
/// <param name="parameters">Parameters needed for the command</param>
595-
/// <returns>A task object representing the asynchronous operation</returns>
596-
internal Task<Response> InternalExecuteAsync(string driverCommandToExecute,
597-
Dictionary<string, object> parameters)
598-
{
599-
return this.ExecuteAsync(driverCommandToExecute, parameters);
600-
}
601-
602579
/// <summary>
603580
/// Executes a command with this driver.
604581
/// </summary>
605582
/// <param name="driverCommandToExecute">A <see cref="DriverCommand"/> value representing the command to execute.</param>
606583
/// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing the names and values of the parameters of the command.</param>
607584
/// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns>
608-
protected virtual Response Execute(string driverCommandToExecute,
585+
protected internal virtual Response Execute(string driverCommandToExecute,
609586
Dictionary<string, object> parameters)
610587
{
611588
return Task.Run(() => this.ExecuteAsync(driverCommandToExecute, parameters)).GetAwaiter().GetResult();
@@ -617,7 +594,7 @@ protected virtual Response Execute(string driverCommandToExecute,
617594
/// <param name="driverCommandToExecute">A <see cref="DriverCommand"/> value representing the command to execute.</param>
618595
/// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing the names and values of the parameters of the command.</param>
619596
/// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns>
620-
protected virtual async Task<Response> ExecuteAsync(string driverCommandToExecute, Dictionary<string, object> parameters)
597+
protected internal virtual async Task<Response> ExecuteAsync(string driverCommandToExecute, Dictionary<string, object> parameters)
621598
{
622599
Command commandToExecute = new Command(SessionId, driverCommandToExecute, parameters);
623600

dotnet/src/webdriver/WebElement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ Dictionary<string, object> IWebDriverObjectReference.ToDictionary()
684684
/// <returns>The <see cref="Response"/> object containing the result of the command execution.</returns>
685685
protected virtual Response Execute(string commandToExecute, Dictionary<string, object> parameters)
686686
{
687-
return this.driver.InternalExecute(commandToExecute, parameters);
687+
return this.driver.Execute(commandToExecute, parameters);
688688
}
689689

690690
private static string GetAtom(string atomResourceName)

0 commit comments

Comments
 (0)