diff --git a/dotnet/src/webdriver/Chromium/ChromiumAndroidOptions.cs b/dotnet/src/webdriver/Chromium/ChromiumAndroidOptions.cs
index 02ed81b3c97a0..726aae094d17b 100644
--- a/dotnet/src/webdriver/Chromium/ChromiumAndroidOptions.cs
+++ b/dotnet/src/webdriver/Chromium/ChromiumAndroidOptions.cs
@@ -19,6 +19,8 @@
using OpenQA.Selenium.Internal;
+#nullable enable
+
namespace OpenQA.Selenium.Chromium
{
///
@@ -26,9 +28,6 @@ namespace OpenQA.Selenium.Chromium
///
public class ChromiumAndroidOptions : AndroidOptions
{
- private string androidProcess;
- private bool androidUseRunningApp;
-
///
/// Initializes a new instance of the class.
///
@@ -40,19 +39,11 @@ public ChromiumAndroidOptions(string androidPackage) : base(androidPackage)
///
/// Gets or sets a value indicating whether to use an already running app.
///
- public bool UseRunningApp
- {
- get { return this.androidUseRunningApp; }
- set { this.androidUseRunningApp = value; }
- }
+ public bool UseRunningApp { get; set; }
///
/// Gets or sets the process name of the Activity hosting the app.
///
- public string AndroidProcess
- {
- get { return this.androidProcess; }
- set { this.androidProcess = value; }
- }
+ public string? AndroidProcess { get; set; }
}
}
diff --git a/dotnet/src/webdriver/Chromium/ChromiumMobileEmulationDeviceSettings.cs b/dotnet/src/webdriver/Chromium/ChromiumMobileEmulationDeviceSettings.cs
index b52cccd6b63f3..849a24a9a469d 100644
--- a/dotnet/src/webdriver/Chromium/ChromiumMobileEmulationDeviceSettings.cs
+++ b/dotnet/src/webdriver/Chromium/ChromiumMobileEmulationDeviceSettings.cs
@@ -17,6 +17,8 @@
// under the License.
//
+#nullable enable
+
namespace OpenQA.Selenium.Chromium
{
///
@@ -25,12 +27,6 @@ namespace OpenQA.Selenium.Chromium
///
public class ChromiumMobileEmulationDeviceSettings
{
- private string userAgent = string.Empty;
- private long width;
- private long height;
- private double pixelRatio;
- private bool enableTouchEvents = true;
-
///
/// Initializes a new instance of the class.
///
@@ -43,59 +39,39 @@ public ChromiumMobileEmulationDeviceSettings()
///
/// The user agent string to be used by the browser when emulating
/// a mobile device.
- public ChromiumMobileEmulationDeviceSettings(string userAgent)
+ public ChromiumMobileEmulationDeviceSettings(string? userAgent)
{
- this.userAgent = userAgent;
+ this.UserAgent = userAgent;
}
///
/// Gets or sets the user agent string to be used by the browser when emulating
/// a mobile device.
///
- public string UserAgent
- {
- get { return this.userAgent; }
- set { this.userAgent = value; }
- }
+ public string? UserAgent { get; set; }
///
/// Gets or sets the width in pixels to be used by the browser when emulating
/// a mobile device.
///
- public long Width
- {
- get { return this.width; }
- set { this.width = value; }
- }
+ public long Width { get; set; }
///
/// Gets or sets the height in pixels to be used by the browser when emulating
/// a mobile device.
///
- public long Height
- {
- get { return this.height; }
- set { this.height = value; }
- }
+ public long Height { get; set; }
///
/// Gets or sets the pixel ratio to be used by the browser when emulating
/// a mobile device.
///
- public double PixelRatio
- {
- get { return this.pixelRatio; }
- set { this.pixelRatio = value; }
- }
+ public double PixelRatio { get; set; }
///
/// Gets or sets a value indicating whether touch events should be enabled by
/// the browser when emulating a mobile device. Defaults to .
///
- public bool EnableTouchEvents
- {
- get { return this.enableTouchEvents; }
- set { this.enableTouchEvents = value; }
- }
+ public bool EnableTouchEvents { get; set; } = true;
}
}
diff --git a/dotnet/src/webdriver/Chromium/ChromiumNetworkConditions.cs b/dotnet/src/webdriver/Chromium/ChromiumNetworkConditions.cs
index b117ce2819bc7..78329f1722edb 100644
--- a/dotnet/src/webdriver/Chromium/ChromiumNetworkConditions.cs
+++ b/dotnet/src/webdriver/Chromium/ChromiumNetworkConditions.cs
@@ -21,6 +21,8 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
+#nullable enable
+
namespace OpenQA.Selenium.Chromium
{
///
@@ -28,8 +30,6 @@ namespace OpenQA.Selenium.Chromium
///
public class ChromiumNetworkConditions
{
- private bool offline;
- private TimeSpan latency = TimeSpan.Zero;
private long downloadThroughput = 0;
private long uploadThroughput = 0;
@@ -37,21 +37,13 @@ public class ChromiumNetworkConditions
/// Gets or sets a value indicating whether the network is offline. Defaults to .
///
[JsonPropertyName("offline")]
- public bool IsOffline
- {
- get { return this.offline; }
- set { this.offline = value; }
- }
+ public bool IsOffline { get; set; }
///
/// Gets or sets the simulated latency of the connection. Typically given in milliseconds.
///
[JsonIgnore]
- public TimeSpan Latency
- {
- get { return this.latency; }
- set { this.latency = value; }
- }
+ public TimeSpan Latency { get; set; } = TimeSpan.Zero;
///
/// Gets or sets the throughput of the network connection in bytes/second for downloading.
@@ -59,12 +51,12 @@ public TimeSpan Latency
[JsonPropertyName("download_throughput")]
public long DownloadThroughput
{
- get { return this.downloadThroughput; }
+ get => this.downloadThroughput;
set
{
if (value < 0)
{
- throw new WebDriverException("Downlod throughput cannot be negative.");
+ throw new WebDriverException("Download throughput cannot be negative.");
}
this.downloadThroughput = value;
@@ -77,7 +69,7 @@ public long DownloadThroughput
[JsonPropertyName("upload_throughput")]
public long UploadThroughput
{
- get { return this.uploadThroughput; }
+ get => this.uploadThroughput;
set
{
if (value < 0)
@@ -92,13 +84,7 @@ public long UploadThroughput
[JsonPropertyName("latency")]
[JsonInclude]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
- internal long? SerializableLatency
- {
- get
- {
- return Convert.ToInt64(this.latency.TotalMilliseconds);
- }
- }
+ internal long? SerializableLatency => Convert.ToInt64(this.Latency.TotalMilliseconds);
///
/// Creates a ChromiumNetworkConditions object from a dictionary of key-value pairs.
@@ -108,24 +94,24 @@ internal long? SerializableLatency
public static ChromiumNetworkConditions FromDictionary(Dictionary dictionary)
{
ChromiumNetworkConditions conditions = new ChromiumNetworkConditions();
- if (dictionary.ContainsKey("offline"))
+ if (dictionary.TryGetValue("offline", out object? offline))
{
- conditions.IsOffline = (bool)dictionary["offline"];
+ conditions.IsOffline = (bool)offline;
}
- if (dictionary.ContainsKey("latency"))
+ if (dictionary.TryGetValue("latency", out object? latency))
{
- conditions.Latency = TimeSpan.FromMilliseconds(Convert.ToDouble(dictionary["latency"]));
+ conditions.Latency = TimeSpan.FromMilliseconds(Convert.ToDouble(latency));
}
- if (dictionary.ContainsKey("upload_throughput"))
+ if (dictionary.TryGetValue("upload_throughput", out object? uploadThroughput))
{
- conditions.UploadThroughput = (long)dictionary["upload_throughput"];
+ conditions.UploadThroughput = (long)uploadThroughput;
}
- if (dictionary.ContainsKey("download_throughput"))
+ if (dictionary.TryGetValue("download_throughput", out object? downloadThroughput))
{
- conditions.DownloadThroughput = (long)dictionary["download_throughput"];
+ conditions.DownloadThroughput = (long)downloadThroughput;
}
return conditions;
@@ -135,11 +121,12 @@ public static ChromiumNetworkConditions FromDictionary(Dictionary
/// The throughput of the network connection in bytes/second for both upload and download.
+ /// If is negative.
public void SetBidirectionalThroughput(long throughput)
{
if (throughput < 0)
{
- throw new ArgumentException("Throughput values cannot be negative.", nameof(throughput));
+ throw new ArgumentOutOfRangeException(nameof(throughput), "Throughput values cannot be negative.");
}
this.uploadThroughput = throughput;
diff --git a/dotnet/src/webdriver/Chromium/ChromiumPerformanceLoggingPreferences.cs b/dotnet/src/webdriver/Chromium/ChromiumPerformanceLoggingPreferences.cs
index 9521fdb294193..65761bdedc645 100644
--- a/dotnet/src/webdriver/Chromium/ChromiumPerformanceLoggingPreferences.cs
+++ b/dotnet/src/webdriver/Chromium/ChromiumPerformanceLoggingPreferences.cs
@@ -20,6 +20,8 @@
using System;
using System.Collections.Generic;
+#nullable enable
+
namespace OpenQA.Selenium.Chromium
{
///
@@ -28,49 +30,36 @@ namespace OpenQA.Selenium.Chromium
///
public class ChromiumPerformanceLoggingPreferences
{
- private bool isCollectingNetworkEvents = true;
- private bool isCollectingPageEvents = true;
private TimeSpan bufferUsageReportingInterval = TimeSpan.FromMilliseconds(1000);
- private List tracingCategories = new List();
+ private readonly List tracingCategories = new List();
///
/// Gets or sets a value indicating whether Chromium will collect events from the Network domain.
/// Defaults to .
///
- public bool IsCollectingNetworkEvents
- {
- get { return this.isCollectingNetworkEvents; }
- set { this.isCollectingNetworkEvents = value; }
- }
+ public bool IsCollectingNetworkEvents { get; set; } = true;
///
/// Gets or sets a value indicating whether Chromium will collect events from the Page domain.
/// Defaults to .
///
- public bool IsCollectingPageEvents
- {
- get { return this.isCollectingPageEvents; }
- set { this.isCollectingPageEvents = value; }
- }
+ public bool IsCollectingPageEvents { get; set; } = true;
///
/// Gets or sets the interval between Chromium DevTools trace buffer usage events.
/// Defaults to 1000 milliseconds.
///
/// Thrown when an attempt is made to set
- /// the value to a time span of less tnan or equal to zero milliseconds.
+ /// the value to a time span of less than or equal to zero.
public TimeSpan BufferUsageReportingInterval
{
- get
- {
- return this.bufferUsageReportingInterval;
- }
+ get => this.bufferUsageReportingInterval;
set
{
- if (value.TotalMilliseconds <= 0)
+ if (value <= TimeSpan.Zero)
{
- throw new ArgumentException("Interval must be greater than zero.");
+ throw new ArgumentException("Interval must be greater than zero.", nameof(value));
}
this.bufferUsageReportingInterval = value;
@@ -80,23 +69,13 @@ public TimeSpan BufferUsageReportingInterval
///
/// Gets a comma-separated list of the categories for which tracing is enabled.
///
- public string TracingCategories
- {
- get
- {
- if (this.tracingCategories.Count == 0)
- {
- return string.Empty;
- }
-
- return string.Join(",", this.tracingCategories.ToArray());
- }
- }
+ public string TracingCategories => string.Join(",", this.tracingCategories);
///
/// Adds a single category to the list of Chromium tracing categories for which events should be collected.
///
/// The category to add.
+ /// If is or .
public void AddTracingCategory(string category)
{
if (string.IsNullOrEmpty(category))
@@ -111,15 +90,17 @@ public void AddTracingCategory(string category)
/// Adds categories to the list of Chromium tracing categories for which events should be collected.
///
/// An array of categories to add.
+ /// If is .
public void AddTracingCategories(params string[] categoriesToAdd)
{
- this.AddTracingCategories(new List(categoriesToAdd));
+ this.AddTracingCategories((IEnumerable)categoriesToAdd);
}
///
/// Adds categories to the list of Chromium tracing categories for which events should be collected.
///
/// An object of categories to add.
+ /// If is .
public void AddTracingCategories(IEnumerable categoriesToAdd)
{
if (categoriesToAdd == null)