diff --git a/dotnet/src/webdriver/DevTools/Target.cs b/dotnet/src/webdriver/DevTools/Target.cs index ea35c4c815dfa..8f1925429e82e 100644 --- a/dotnet/src/webdriver/DevTools/Target.cs +++ b/dotnet/src/webdriver/DevTools/Target.cs @@ -21,6 +21,8 @@ using System.Collections.ObjectModel; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -31,12 +33,12 @@ public abstract class Target /// /// Occurs when a target is detached. /// - public event EventHandler TargetDetached; + public event EventHandler? TargetDetached; /// /// Occurs when a target is attached. /// - public event EventHandler TargetAttached; + public event EventHandler? TargetAttached; /// /// Asynchronously gets the targets available for this session. @@ -46,7 +48,7 @@ public abstract class Target /// contains the list of objects describing the /// targets available for this session. /// - public abstract Task> GetTargets(Object settings = null); + public abstract Task> GetTargets(object? settings = null); /// /// Asynchronously attaches to a target. @@ -66,7 +68,7 @@ public abstract class Target /// /// A task representing the asynchronous detach operation. /// - public abstract Task DetachFromTarget(string sessionId = null, string targetId = null); + public abstract Task DetachFromTarget(string? sessionId = null, string? targetId = null); /// /// Asynchronously sets the DevTools Protocol connection to automatically attach to new targets. diff --git a/dotnet/src/webdriver/DevTools/TargetInfo.cs b/dotnet/src/webdriver/DevTools/TargetInfo.cs index 6e7230a6a5029..f2248f9300d5d 100644 --- a/dotnet/src/webdriver/DevTools/TargetInfo.cs +++ b/dotnet/src/webdriver/DevTools/TargetInfo.cs @@ -17,6 +17,8 @@ // under the License. // +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -24,39 +26,60 @@ namespace OpenQA.Selenium.DevTools /// public class TargetInfo { + /// + /// Initializes a new instance of the type. + /// + /// The ID of the target. + /// The type of target. + /// The title of the target. + /// The URL of the target. + /// Whether the protocol is attached to the target. + /// The ID of the opener of the target. + /// The browser context ID. + public TargetInfo(string targetId, string type, string title, string url, bool isAttached, string? openerId, string? browserContextId) + { + this.TargetId = targetId; + this.Type = type; + this.Title = title; + this.Url = url; + this.IsAttached = isAttached; + this.OpenerId = openerId; + this.BrowserContextId = browserContextId; + } + /// /// Gets the ID of the target. /// - public string TargetId { get; internal set; } + public string TargetId { get; } /// /// Gets the type of target. /// - public string Type { get; internal set; } + public string Type { get; } /// /// Gets the title of the target. /// - public string Title { get; internal set; } + public string Title { get; } /// /// Gets the URL of the target. /// - public string Url { get; internal set; } + public string Url { get; } /// /// Gets a value indicating if the protocol is attached to the target. /// - public bool IsAttached { get; internal set; } + public bool IsAttached { get; } /// /// Gets the ID of the opener of the target. /// - public string OpenerId { get; internal set; } + public string? OpenerId { get; } /// /// Gets the browser context ID. /// - public string BrowserContextId { get; internal set; } + public string? BrowserContextId { get; } } } diff --git a/dotnet/src/webdriver/DevTools/v130/V130Target.cs b/dotnet/src/webdriver/DevTools/v130/V130Target.cs index 97dcc12fa6b1c..4b43db8f8af35 100644 --- a/dotnet/src/webdriver/DevTools/v130/V130Target.cs +++ b/dotnet/src/webdriver/DevTools/v130/V130Target.cs @@ -23,6 +23,8 @@ using System.Collections.ObjectModel; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.DevTools.V130 { /// @@ -30,15 +32,16 @@ namespace OpenQA.Selenium.DevTools.V130 /// public class V130Target : DevTools.Target { - private TargetAdapter adapter; + private readonly TargetAdapter adapter; /// /// Initializes a new instance of the class. /// /// The adapter for the Target domain. + /// If is . public V130Target(TargetAdapter adapter) { - this.adapter = adapter; + this.adapter = adapter ?? throw new ArgumentNullException(nameof(adapter)); adapter.DetachedFromTarget += OnDetachedFromTarget; adapter.AttachedToTarget += OnAttachedToTarget; } @@ -51,28 +54,26 @@ public V130Target(TargetAdapter adapter) /// contains the list of objects describing the /// targets available for this session. /// - public override async Task> GetTargets(Object settings = null) - + public override async Task> GetTargets(object? settings = null) { - List targets = new List(); - if (settings == null) - { - settings = new GetTargetsCommandSettings(); - } + settings ??= new GetTargetsCommandSettings(); + var response = await adapter.GetTargets((GetTargetsCommandSettings)settings).ConfigureAwait(false); + + List targets = new List(response.TargetInfos.Length); for (int i = 0; i < response.TargetInfos.Length; i++) { var targetInfo = response.TargetInfos[i]; - var mapped = new TargetInfo() - { - TargetId = targetInfo.TargetId, - Title = targetInfo.Title, - Type = targetInfo.Type, - Url = targetInfo.Url, - OpenerId = targetInfo.OpenerId, - BrowserContextId = targetInfo.BrowserContextId, - IsAttached = targetInfo.Attached - }; + var mapped = new TargetInfo + ( + targetId: targetInfo.TargetId, + title: targetInfo.Title, + type: targetInfo.Type, + url: targetInfo.Url, + openerId: targetInfo.OpenerId, + browserContextId: targetInfo.BrowserContextId, + isAttached: targetInfo.Attached + ); targets.Add(mapped); } @@ -99,7 +100,7 @@ public override async Task AttachToTarget(string targetId) /// The ID of the session of the target from which to detach. /// The ID of the target from which to detach. /// A task representing the asynchronous detach operation. - public override async Task DetachFromTarget(string sessionId = null, string targetId = null) + public override async Task DetachFromTarget(string? sessionId = null, string? targetId = null) { await adapter.DetachFromTarget(new DetachFromTargetCommandSettings() { @@ -117,23 +118,23 @@ public override async Task SetAutoAttach() await adapter.SetAutoAttach(new SetAutoAttachCommandSettings() { AutoAttach = true, WaitForDebuggerOnStart = false, Flatten = true }).ConfigureAwait(false); } - private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e) + private void OnDetachedFromTarget(object? sender, DetachedFromTargetEventArgs e) { this.OnTargetDetached(new TargetDetachedEventArgs(e.SessionId, e.TargetId)); } - private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) + private void OnAttachedToTarget(object? sender, AttachedToTargetEventArgs e) { var targetInfo = e.TargetInfo == null ? null : new TargetInfo - { - BrowserContextId = e.TargetInfo.BrowserContextId, - IsAttached = e.TargetInfo.Attached, - OpenerId = e.TargetInfo.OpenerId, - TargetId = e.TargetInfo.TargetId, - Title = e.TargetInfo.Title, - Type = e.TargetInfo.Type, - Url = e.TargetInfo.Url - }; + ( + browserContextId: e.TargetInfo.BrowserContextId, + isAttached: e.TargetInfo.Attached, + openerId: e.TargetInfo.OpenerId, + targetId: e.TargetInfo.TargetId, + title: e.TargetInfo.Title, + type: e.TargetInfo.Type, + url: e.TargetInfo.Url + ); this.OnTargetAttached(new TargetAttachedEventArgs ( diff --git a/dotnet/src/webdriver/DevTools/v131/V131Target.cs b/dotnet/src/webdriver/DevTools/v131/V131Target.cs index 8224d797bc8fe..914e8a75ca8c9 100644 --- a/dotnet/src/webdriver/DevTools/v131/V131Target.cs +++ b/dotnet/src/webdriver/DevTools/v131/V131Target.cs @@ -23,6 +23,8 @@ using System.Collections.ObjectModel; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.DevTools.V131 { /// @@ -30,15 +32,16 @@ namespace OpenQA.Selenium.DevTools.V131 /// public class V131Target : DevTools.Target { - private TargetAdapter adapter; + private readonly TargetAdapter adapter; /// /// Initializes a new instance of the class. /// /// The adapter for the Target domain. + /// If is . public V131Target(TargetAdapter adapter) { - this.adapter = adapter; + this.adapter = adapter ?? throw new ArgumentNullException(nameof(adapter)); adapter.DetachedFromTarget += OnDetachedFromTarget; adapter.AttachedToTarget += OnAttachedToTarget; } @@ -51,28 +54,26 @@ public V131Target(TargetAdapter adapter) /// contains the list of objects describing the /// targets available for this session. /// - public override async Task> GetTargets(Object settings = null) - + public override async Task> GetTargets(object? settings = null) { - List targets = new List(); - if (settings == null) - { - settings = new GetTargetsCommandSettings(); - } + settings ??= new GetTargetsCommandSettings(); + var response = await adapter.GetTargets((GetTargetsCommandSettings)settings).ConfigureAwait(false); + + List targets = new List(response.TargetInfos.Length); for (int i = 0; i < response.TargetInfos.Length; i++) { var targetInfo = response.TargetInfos[i]; - var mapped = new TargetInfo() - { - TargetId = targetInfo.TargetId, - Title = targetInfo.Title, - Type = targetInfo.Type, - Url = targetInfo.Url, - OpenerId = targetInfo.OpenerId, - BrowserContextId = targetInfo.BrowserContextId, - IsAttached = targetInfo.Attached - }; + var mapped = new TargetInfo + ( + targetId: targetInfo.TargetId, + title: targetInfo.Title, + type: targetInfo.Type, + url: targetInfo.Url, + openerId: targetInfo.OpenerId, + browserContextId: targetInfo.BrowserContextId, + isAttached: targetInfo.Attached + ); targets.Add(mapped); } @@ -99,7 +100,7 @@ public override async Task AttachToTarget(string targetId) /// The ID of the session of the target from which to detach. /// The ID of the target from which to detach. /// A task representing the asynchronous detach operation. - public override async Task DetachFromTarget(string sessionId = null, string targetId = null) + public override async Task DetachFromTarget(string? sessionId = null, string? targetId = null) { await adapter.DetachFromTarget(new DetachFromTargetCommandSettings() { @@ -117,23 +118,23 @@ public override async Task SetAutoAttach() await adapter.SetAutoAttach(new SetAutoAttachCommandSettings() { AutoAttach = true, WaitForDebuggerOnStart = false, Flatten = true }).ConfigureAwait(false); } - private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e) + private void OnDetachedFromTarget(object? sender, DetachedFromTargetEventArgs e) { this.OnTargetDetached(new TargetDetachedEventArgs(e.SessionId, e.TargetId)); } - private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) + private void OnAttachedToTarget(object? sender, AttachedToTargetEventArgs e) { var targetInfo = e.TargetInfo == null ? null : new TargetInfo - { - BrowserContextId = e.TargetInfo.BrowserContextId, - IsAttached = e.TargetInfo.Attached, - OpenerId = e.TargetInfo.OpenerId, - TargetId = e.TargetInfo.TargetId, - Title = e.TargetInfo.Title, - Type = e.TargetInfo.Type, - Url = e.TargetInfo.Url - }; + ( + browserContextId: e.TargetInfo.BrowserContextId, + isAttached: e.TargetInfo.Attached, + openerId: e.TargetInfo.OpenerId, + targetId: e.TargetInfo.TargetId, + title: e.TargetInfo.Title, + type: e.TargetInfo.Type, + url: e.TargetInfo.Url + ); this.OnTargetAttached(new TargetAttachedEventArgs ( diff --git a/dotnet/src/webdriver/DevTools/v132/V132Target.cs b/dotnet/src/webdriver/DevTools/v132/V132Target.cs index 56bf120835eb5..20791a390881b 100644 --- a/dotnet/src/webdriver/DevTools/v132/V132Target.cs +++ b/dotnet/src/webdriver/DevTools/v132/V132Target.cs @@ -23,6 +23,8 @@ using System.Collections.ObjectModel; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.DevTools.V132 { /// @@ -30,15 +32,16 @@ namespace OpenQA.Selenium.DevTools.V132 /// public class V132Target : DevTools.Target { - private TargetAdapter adapter; + private readonly TargetAdapter adapter; /// /// Initializes a new instance of the class. /// /// The adapter for the Target domain. + /// If is . public V132Target(TargetAdapter adapter) { - this.adapter = adapter; + this.adapter = adapter ?? throw new ArgumentNullException(nameof(adapter)); adapter.DetachedFromTarget += OnDetachedFromTarget; adapter.AttachedToTarget += OnAttachedToTarget; } @@ -51,28 +54,26 @@ public V132Target(TargetAdapter adapter) /// contains the list of objects describing the /// targets available for this session. /// - public override async Task> GetTargets(Object settings = null) - + public override async Task> GetTargets(object? settings = null) { - List targets = new List(); - if (settings == null) - { - settings = new GetTargetsCommandSettings(); - } + settings ??= new GetTargetsCommandSettings(); + var response = await adapter.GetTargets((GetTargetsCommandSettings)settings).ConfigureAwait(false); + + List targets = new List(response.TargetInfos.Length); for (int i = 0; i < response.TargetInfos.Length; i++) { var targetInfo = response.TargetInfos[i]; - var mapped = new TargetInfo() - { - TargetId = targetInfo.TargetId, - Title = targetInfo.Title, - Type = targetInfo.Type, - Url = targetInfo.Url, - OpenerId = targetInfo.OpenerId, - BrowserContextId = targetInfo.BrowserContextId, - IsAttached = targetInfo.Attached - }; + var mapped = new TargetInfo + ( + targetId: targetInfo.TargetId, + title: targetInfo.Title, + type: targetInfo.Type, + url: targetInfo.Url, + openerId: targetInfo.OpenerId, + browserContextId: targetInfo.BrowserContextId, + isAttached: targetInfo.Attached + ); targets.Add(mapped); } @@ -99,7 +100,7 @@ public override async Task AttachToTarget(string targetId) /// The ID of the session of the target from which to detach. /// The ID of the target from which to detach. /// A task representing the asynchronous detach operation. - public override async Task DetachFromTarget(string sessionId = null, string targetId = null) + public override async Task DetachFromTarget(string? sessionId = null, string? targetId = null) { await adapter.DetachFromTarget(new DetachFromTargetCommandSettings() { @@ -117,23 +118,23 @@ public override async Task SetAutoAttach() await adapter.SetAutoAttach(new SetAutoAttachCommandSettings() { AutoAttach = true, WaitForDebuggerOnStart = false, Flatten = true }).ConfigureAwait(false); } - private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e) + private void OnDetachedFromTarget(object? sender, DetachedFromTargetEventArgs e) { this.OnTargetDetached(new TargetDetachedEventArgs(e.SessionId, e.TargetId)); } - private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) + private void OnAttachedToTarget(object? sender, AttachedToTargetEventArgs e) { var targetInfo = e.TargetInfo == null ? null : new TargetInfo - { - BrowserContextId = e.TargetInfo.BrowserContextId, - IsAttached = e.TargetInfo.Attached, - OpenerId = e.TargetInfo.OpenerId, - TargetId = e.TargetInfo.TargetId, - Title = e.TargetInfo.Title, - Type = e.TargetInfo.Type, - Url = e.TargetInfo.Url - }; + ( + browserContextId: e.TargetInfo.BrowserContextId, + isAttached: e.TargetInfo.Attached, + openerId: e.TargetInfo.OpenerId, + targetId: e.TargetInfo.TargetId, + title: e.TargetInfo.Title, + type: e.TargetInfo.Type, + url: e.TargetInfo.Url + ); this.OnTargetAttached(new TargetAttachedEventArgs ( diff --git a/dotnet/src/webdriver/DevTools/v85/V85Target.cs b/dotnet/src/webdriver/DevTools/v85/V85Target.cs index 5a506796f9380..fb40a4be8f368 100644 --- a/dotnet/src/webdriver/DevTools/v85/V85Target.cs +++ b/dotnet/src/webdriver/DevTools/v85/V85Target.cs @@ -23,6 +23,8 @@ using System.Collections.ObjectModel; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.DevTools.V85 { /// @@ -30,15 +32,16 @@ namespace OpenQA.Selenium.DevTools.V85 /// public class V85Target : DevTools.Target { - private TargetAdapter adapter; + private readonly TargetAdapter adapter; /// /// Initializes a new instance of the class. /// /// The adapter for the Target domain. + /// If is . public V85Target(TargetAdapter adapter) { - this.adapter = adapter; + this.adapter = adapter ?? throw new ArgumentNullException(nameof(adapter)); adapter.DetachedFromTarget += OnDetachedFromTarget; adapter.AttachedToTarget += OnAttachedToTarget; } @@ -51,23 +54,24 @@ public V85Target(TargetAdapter adapter) /// contains the list of objects describing the /// targets available for this session. /// - public override async Task> GetTargets(Object settings = null) + public override async Task> GetTargets(object? settings = null) { - List targets = new List(); var response = await adapter.GetTargets().ConfigureAwait(false); + + List targets = new List(response.TargetInfos.Length); for (int i = 0; i < response.TargetInfos.Length; i++) { var targetInfo = response.TargetInfos[i]; - var mapped = new TargetInfo() - { - TargetId = targetInfo.TargetId, - Title = targetInfo.Title, - Type = targetInfo.Type, - Url = targetInfo.Url, - OpenerId = targetInfo.OpenerId, - BrowserContextId = targetInfo.BrowserContextId, - IsAttached = targetInfo.Attached - }; + var mapped = new TargetInfo + ( + targetId: targetInfo.TargetId, + title: targetInfo.Title, + type: targetInfo.Type, + url: targetInfo.Url, + openerId: targetInfo.OpenerId, + browserContextId: targetInfo.BrowserContextId, + isAttached: targetInfo.Attached + ); targets.Add(mapped); } @@ -94,7 +98,7 @@ public override async Task AttachToTarget(string targetId) /// The ID of the session of the target from which to detach. /// The ID of the target from which to detach. /// A task representing the asynchronous detach operation. - public override async Task DetachFromTarget(string sessionId = null, string targetId = null) + public override async Task DetachFromTarget(string? sessionId = null, string? targetId = null) { await adapter.DetachFromTarget(new DetachFromTargetCommandSettings() { @@ -112,23 +116,23 @@ public override async Task SetAutoAttach() await adapter.SetAutoAttach(new SetAutoAttachCommandSettings() { AutoAttach = true, WaitForDebuggerOnStart = false, Flatten = true }).ConfigureAwait(false); } - private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e) + private void OnDetachedFromTarget(object? sender, DetachedFromTargetEventArgs e) { this.OnTargetDetached(new TargetDetachedEventArgs(e.SessionId, e.TargetId)); } - private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) + private void OnAttachedToTarget(object? sender, AttachedToTargetEventArgs e) { var targetInfo = e.TargetInfo == null ? null : new TargetInfo - { - BrowserContextId = e.TargetInfo.BrowserContextId, - IsAttached = e.TargetInfo.Attached, - OpenerId = e.TargetInfo.OpenerId, - TargetId = e.TargetInfo.TargetId, - Title = e.TargetInfo.Title, - Type = e.TargetInfo.Type, - Url = e.TargetInfo.Url - }; + ( + browserContextId: e.TargetInfo.BrowserContextId, + isAttached: e.TargetInfo.Attached, + openerId: e.TargetInfo.OpenerId, + targetId: e.TargetInfo.TargetId, + title: e.TargetInfo.Title, + type: e.TargetInfo.Type, + url: e.TargetInfo.Url + ); this.OnTargetAttached(new TargetAttachedEventArgs (