Skip to content

Commit 0353a65

Browse files
committed
[dotnet] Add NRT to Manage() and friends
1 parent 6b40d9e commit 0353a65

File tree

18 files changed

+140
-64
lines changed

18 files changed

+140
-64
lines changed

dotnet/src/webdriver/Alert.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919
using System;
2020
using System.Collections.Generic;
2121

22+
#nullable enable
23+
2224
namespace OpenQA.Selenium
2325
{
2426
/// <summary>
2527
/// Defines the interface through which the user can manipulate JavaScript alerts.
2628
/// </summary>
2729
internal class Alert : IAlert
2830
{
29-
private WebDriver driver;
31+
private readonly WebDriver driver;
3032

3133
/// <summary>
3234
/// Initializes a new instance of the <see cref="Alert"/> class.
@@ -45,7 +47,7 @@ public string Text
4547
get
4648
{
4749
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetAlertText, null);
48-
return commandResponse.Value.ToString();
50+
return commandResponse.Value.ToString()!;
4951
}
5052
}
5153

@@ -69,6 +71,7 @@ public void Accept()
6971
/// Sends keys to the alert.
7072
/// </summary>
7173
/// <param name="keysToSend">The keystrokes to send.</param>
74+
/// <exception cref="ArgumentNullException">If <paramref name="keysToSend" /> is null.</exception>
7275
public void SendKeys(string keysToSend)
7376
{
7477
if (keysToSend == null)

dotnet/src/webdriver/Cookie.cs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
using System.Linq;
2424
using System.Text.Json.Serialization;
2525

26+
#nullable enable
27+
2628
namespace OpenQA.Selenium
2729
{
2830
/// <summary>
@@ -33,9 +35,9 @@ public class Cookie
3335
{
3436
private string cookieName;
3537
private string cookieValue;
36-
private string cookiePath;
37-
private string cookieDomain;
38-
private string sameSite;
38+
private string? cookiePath;
39+
private string? cookieDomain;
40+
private string? sameSite;
3941
private bool isHttpOnly;
4042
private bool secure;
4143
private DateTime? cookieExpiry;
@@ -64,7 +66,7 @@ public Cookie(string name, string value)
6466
/// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
6567
/// or if it contains a semi-colon.</exception>
6668
/// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
67-
public Cookie(string name, string value, string path)
69+
public Cookie(string name, string value, string? path)
6870
: this(name, value, path, null)
6971
{
7072
}
@@ -80,7 +82,7 @@ public Cookie(string name, string value, string path)
8082
/// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
8183
/// or if it contains a semi-colon.</exception>
8284
/// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
83-
public Cookie(string name, string value, string path, DateTime? expiry)
85+
public Cookie(string name, string value, string? path, DateTime? expiry)
8486
: this(name, value, null, path, expiry)
8587
{
8688
}
@@ -97,7 +99,7 @@ public Cookie(string name, string value, string path, DateTime? expiry)
9799
/// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
98100
/// or if it contains a semi-colon.</exception>
99101
/// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
100-
public Cookie(string name, string value, string domain, string path, DateTime? expiry)
102+
public Cookie(string name, string value, string? domain, string? path, DateTime? expiry)
101103
: this(name, value, domain, path, expiry, false, false, null)
102104
{
103105
}
@@ -117,7 +119,7 @@ public Cookie(string name, string value, string domain, string path, DateTime? e
117119
/// <exception cref="ArgumentException">If the name and value are both an empty string,
118120
/// if the name contains a semi-colon, or if same site value is not valid.</exception>
119121
/// <exception cref="ArgumentNullException">If the name, value or currentUrl is <see langword="null"/>.</exception>
120-
public Cookie(string name, string value, string domain, string path, DateTime? expiry, bool secure, bool isHttpOnly, string sameSite)
122+
public Cookie(string name, string value, string? domain, string? path, DateTime? expiry, bool secure, bool isHttpOnly, string? sameSite)
121123
{
122124
if (name == null)
123125
{
@@ -190,7 +192,7 @@ public string Value
190192
/// </summary>
191193
[JsonPropertyName("domain")]
192194
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
193-
public string Domain
195+
public string? Domain
194196
{
195197
get { return this.cookieDomain; }
196198
}
@@ -200,7 +202,7 @@ public string Domain
200202
/// </summary>
201203
[JsonPropertyName("path")]
202204
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
203-
public virtual string Path
205+
public virtual string? Path
204206
{
205207
get { return this.cookiePath; }
206208
}
@@ -229,7 +231,7 @@ public virtual bool IsHttpOnly
229231
/// </summary>
230232
[JsonPropertyName("sameSite")]
231233
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
232-
public virtual string SameSite
234+
public virtual string? SameSite
233235
{
234236
get { return this.sameSite; }
235237
}
@@ -272,27 +274,28 @@ internal long? ExpirySeconds
272274
/// </summary>
273275
/// <param name="rawCookie">The Dictionary object containing the cookie parameters.</param>
274276
/// <returns>A <see cref="Cookie"/> object with the proper parameters set.</returns>
277+
/// <exception cref="ArgumentNullException">If <paramref name="rawCookie"/> is null.</exception>
275278
public static Cookie FromDictionary(Dictionary<string, object> rawCookie)
276279
{
277280
if (rawCookie == null)
278281
{
279282
throw new ArgumentNullException(nameof(rawCookie), "Dictionary cannot be null");
280283
}
281284

282-
string name = rawCookie["name"].ToString();
285+
string name = rawCookie["name"].ToString()!;
283286
string value = string.Empty;
284287
if (rawCookie["value"] != null)
285288
{
286-
value = rawCookie["value"].ToString();
289+
value = rawCookie["value"].ToString()!;
287290
}
288291

289-
string path = "/";
292+
string? path = "/";
290293
if (rawCookie.ContainsKey("path") && rawCookie["path"] != null)
291294
{
292295
path = rawCookie["path"].ToString();
293296
}
294297

295-
string domain = string.Empty;
298+
string? domain = string.Empty;
296299
if (rawCookie.ContainsKey("domain") && rawCookie["domain"] != null)
297300
{
298301
domain = rawCookie["domain"].ToString();
@@ -307,16 +310,16 @@ public static Cookie FromDictionary(Dictionary<string, object> rawCookie)
307310
bool secure = false;
308311
if (rawCookie.ContainsKey("secure") && rawCookie["secure"] != null)
309312
{
310-
secure = bool.Parse(rawCookie["secure"].ToString());
313+
secure = bool.Parse(rawCookie["secure"].ToString()!);
311314
}
312315

313316
bool isHttpOnly = false;
314317
if (rawCookie.ContainsKey("httpOnly") && rawCookie["httpOnly"] != null)
315318
{
316-
isHttpOnly = bool.Parse(rawCookie["httpOnly"].ToString());
319+
isHttpOnly = bool.Parse(rawCookie["httpOnly"].ToString()!);
317320
}
318321

319-
string sameSite = null;
322+
string? sameSite = null;
320323
if (rawCookie.ContainsKey("sameSite") && rawCookie["sameSite"] != null)
321324
{
322325
sameSite = rawCookie["sameSite"].ToString();
@@ -347,10 +350,10 @@ public override string ToString()
347350
/// <returns><see langword="true"/> if the specified <see cref="object">Object</see>
348351
/// is equal to the current <see cref="object">Object</see>; otherwise,
349352
/// <see langword="false"/>.</returns>
350-
public override bool Equals(object obj)
353+
public override bool Equals(object? obj)
351354
{
352355
// Two cookies are equal if the name and value match
353-
Cookie cookie = obj as Cookie;
356+
Cookie? cookie = obj as Cookie;
354357

355358
if (this == obj)
356359
{
@@ -367,7 +370,7 @@ public override bool Equals(object obj)
367370
return false;
368371
}
369372

370-
return !(this.cookieValue != null ? !this.cookieValue.Equals(cookie.cookieValue) : cookie.Value != null);
373+
return string.Equals(this.cookieValue, cookie.cookieValue);
371374
}
372375

373376
/// <summary>
@@ -379,12 +382,12 @@ public override int GetHashCode()
379382
return this.cookieName.GetHashCode();
380383
}
381384

382-
private static string StripPort(string domain)
385+
private static string? StripPort(string? domain)
383386
{
384-
return string.IsNullOrEmpty(domain) ? null : domain.Split(':')[0];
387+
return string.IsNullOrEmpty(domain) ? null : domain!.Split(':')[0];
385388
}
386389

387-
private static DateTime? ConvertExpirationTime(string expirationTime)
390+
private static DateTime? ConvertExpirationTime(string? expirationTime)
388391
{
389392
DateTime? expires = null;
390393
double seconds = 0;

dotnet/src/webdriver/CookieJar.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020
using System.Collections.Generic;
2121
using System.Collections.ObjectModel;
2222

23+
#nullable enable
24+
2325
namespace OpenQA.Selenium
2426
{
2527
/// <summary>
2628
/// Defines an interface allowing the user to manipulate cookies on the current page.
2729
/// </summary>
2830
internal class CookieJar : ICookieJar
2931
{
30-
private WebDriver driver;
32+
private readonly WebDriver driver;
3133

3234
/// <summary>
3335
/// Initializes a new instance of the <see cref="CookieJar"/> class.
@@ -50,8 +52,14 @@ public ReadOnlyCollection<Cookie> AllCookies
5052
/// Method for creating a cookie in the browser
5153
/// </summary>
5254
/// <param name="cookie"><see cref="Cookie"/> that represents a cookie in the browser</param>
55+
/// <exception cref="ArgumentNullException">If <paramref name="cookie"/> is <see langword="null"/>.</exception>
5356
public void AddCookie(Cookie cookie)
5457
{
58+
if (cookie == null)
59+
{
60+
throw new ArgumentNullException(nameof(cookie));
61+
}
62+
5563
Dictionary<string, object> parameters = new Dictionary<string, object>();
5664
parameters.Add("cookie", cookie);
5765
this.driver.InternalExecute(DriverCommand.AddCookie, parameters);
@@ -61,9 +69,9 @@ public void AddCookie(Cookie cookie)
6169
/// Delete the cookie by passing in the name of the cookie
6270
/// </summary>
6371
/// <param name="name">The name of the cookie that is in the browser</param>
64-
public void DeleteCookieNamed(string name)
72+
public void DeleteCookieNamed(string? name)
6573
{
66-
Dictionary<string, object> parameters = new Dictionary<string, object>();
74+
Dictionary<string, object?> parameters = new Dictionary<string, object?>();
6775
parameters.Add("name", name);
6876
this.driver.InternalExecute(DriverCommand.DeleteCookie, parameters);
6977
}
@@ -72,7 +80,7 @@ public void DeleteCookieNamed(string name)
7280
/// Delete a cookie in the browser by passing in a copy of a cookie
7381
/// </summary>
7482
/// <param name="cookie">An object that represents a copy of the cookie that needs to be deleted</param>
75-
public void DeleteCookie(Cookie cookie)
83+
public void DeleteCookie(Cookie? cookie)
7684
{
7785
if (cookie != null)
7886
{
@@ -92,10 +100,10 @@ public void DeleteAllCookies()
92100
/// Method for returning a getting a cookie by name
93101
/// </summary>
94102
/// <param name="name">name of the cookie that needs to be returned</param>
95-
/// <returns>A Cookie from the name</returns>
96-
public Cookie GetCookieNamed(string name)
103+
/// <returns>A Cookie from the name, or <see langword="null"/> if not found.</returns>
104+
public Cookie? GetCookieNamed(string? name)
97105
{
98-
Cookie cookieToReturn = null;
106+
Cookie? cookieToReturn = null;
99107
if (name != null)
100108
{
101109
ReadOnlyCollection<Cookie> allCookies = this.AllCookies;
@@ -123,12 +131,12 @@ private ReadOnlyCollection<Cookie> GetAllCookies()
123131

124132
try
125133
{
126-
object[] cookies = returned as object[];
134+
object[]? cookies = returned as object[];
127135
if (cookies != null)
128136
{
129137
foreach (object rawCookie in cookies)
130138
{
131-
Dictionary<string, object> cookieDictionary = rawCookie as Dictionary<string, object>;
139+
Dictionary<string, object> cookieDictionary = (Dictionary<string, object>)rawCookie;
132140
if (rawCookie != null)
133141
{
134142
toReturn.Add(Cookie.FromDictionary(cookieDictionary));

dotnet/src/webdriver/ICookieJar.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
// limitations under the License.
1717
// </copyright>
1818

19+
using System;
1920
using System.Collections.ObjectModel;
2021

22+
#nullable enable
23+
2124
namespace OpenQA.Selenium
2225
{
2326
/// <summary>
@@ -34,6 +37,7 @@ public interface ICookieJar
3437
/// Adds a cookie to the current page.
3538
/// </summary>
3639
/// <param name="cookie">The <see cref="Cookie"/> object to be added.</param>
40+
/// <exception cref="ArgumentNullException">If <paramref name="cookie"/> is <see langword="null"/>.</exception>
3741
void AddCookie(Cookie cookie);
3842

3943
/// <summary>
@@ -42,19 +46,19 @@ public interface ICookieJar
4246
/// <param name="name">The name of the cookie to retrieve.</param>
4347
/// <returns>The <see cref="Cookie"/> containing the name. Returns <see langword="null"/>
4448
/// if no cookie with the specified name is found.</returns>
45-
Cookie GetCookieNamed(string name);
49+
Cookie? GetCookieNamed(string? name);
4650

4751
/// <summary>
4852
/// Deletes the specified cookie from the page.
4953
/// </summary>
5054
/// <param name="cookie">The <see cref="Cookie"/> to be deleted.</param>
51-
void DeleteCookie(Cookie cookie);
55+
void DeleteCookie(Cookie? cookie);
5256

5357
/// <summary>
5458
/// Deletes the cookie with the specified name from the page.
5559
/// </summary>
5660
/// <param name="name">The name of the cookie to be deleted.</param>
57-
void DeleteCookieNamed(string name);
61+
void DeleteCookieNamed(string? name);
5862

5963
/// <summary>
6064
/// Deletes all cookies from the page.

dotnet/src/webdriver/ILogs.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
// limitations under the License.
1717
// </copyright>
1818

19+
using System;
1920
using System.Collections.ObjectModel;
2021

22+
#nullable enable
23+
2124
namespace OpenQA.Selenium
2225
{
2326
/// <summary>
@@ -36,6 +39,7 @@ public interface ILogs
3639
/// <param name="logKind">The log for which to retrieve the log entries.
3740
/// Log types can be found in the <see cref="LogType"/> class.</param>
3841
/// <returns>The list of <see cref="LogEntry"/> objects for the specified log.</returns>
42+
/// <exception cref="ArgumentNullException">If <paramref name="logKind"/> is <see langword="null"/>.</exception>
3943
ReadOnlyCollection<LogEntry> GetLog(string logKind);
4044
}
4145
}

dotnet/src/webdriver/INetwork.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
using System;
2020
using System.Threading.Tasks;
2121

22+
#nullable enable
23+
2224
namespace OpenQA.Selenium
2325
{
2426
/// <summary>
@@ -29,18 +31,19 @@ public interface INetwork
2931
/// <summary>
3032
/// Occurs when a browser sends a network request.
3133
/// </summary>
32-
event EventHandler<NetworkRequestSentEventArgs> NetworkRequestSent;
34+
event EventHandler<NetworkRequestSentEventArgs>? NetworkRequestSent;
3335

3436
/// <summary>
3537
/// Occurs when a browser receives a network response.
3638
/// </summary>
37-
event EventHandler<NetworkResponseReceivedEventArgs> NetworkResponseReceived;
39+
event EventHandler<NetworkResponseReceivedEventArgs>? NetworkResponseReceived;
3840

3941
/// <summary>
4042
/// Adds a <see cref="NetworkRequestHandler"/> to examine incoming network requests,
4143
/// and optionally modify the request or provide a response.
4244
/// </summary>
4345
/// <param name="handler">The <see cref="NetworkRequestHandler"/> to add.</param>
46+
/// <exception cref="ArgumentNullException">If <paramref name="handler"/> is <see langword="null"/>.</exception>
4447
void AddRequestHandler(NetworkRequestHandler handler);
4548

4649
/// <summary>

dotnet/src/webdriver/IOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// limitations under the License.
1717
// </copyright>
1818

19+
#nullable enable
20+
1921
namespace OpenQA.Selenium
2022
{
2123
/// <summary>

0 commit comments

Comments
 (0)