diff --git a/dotnet/src/webdriver/Interactions/InputDevice.cs b/dotnet/src/webdriver/Interactions/InputDevice.cs
index 6db6e30a7d8b7..f73c0578e2586 100644
--- a/dotnet/src/webdriver/Interactions/InputDevice.cs
+++ b/dotnet/src/webdriver/Interactions/InputDevice.cs
@@ -21,6 +21,8 @@
using System.Collections.Generic;
using System.Globalization;
+#nullable enable
+
namespace OpenQA.Selenium.Interactions
{
///
@@ -28,12 +30,11 @@ namespace OpenQA.Selenium.Interactions
///
public abstract class InputDevice
{
- private string deviceName;
-
///
/// Initializes a new instance of the class.
///
/// The unique name of the input device represented by this class.
+ /// If is or .
protected InputDevice(string deviceName)
{
if (string.IsNullOrEmpty(deviceName))
@@ -41,16 +42,13 @@ protected InputDevice(string deviceName)
throw new ArgumentException("Device name must not be null or empty", nameof(deviceName));
}
- this.deviceName = deviceName;
+ this.DeviceName = deviceName;
}
///
/// Gets the unique name of this input device.
///
- public string DeviceName
- {
- get { return this.deviceName; }
- }
+ public string DeviceName { get; }
///
/// Gets the kind of device for this input device.
@@ -90,7 +88,7 @@ public Interaction CreatePause(TimeSpan duration)
/// A hash code for the current .
public override int GetHashCode()
{
- return this.deviceName.GetHashCode();
+ return this.DeviceName.GetHashCode();
}
///
@@ -99,7 +97,7 @@ public override int GetHashCode()
/// A string that represents the current .
public override string ToString()
{
- return string.Format(CultureInfo.InvariantCulture, "{0} input device [name: {1}]", this.DeviceKind, this.deviceName);
+ return string.Format(CultureInfo.InvariantCulture, "{0} input device [name: {1}]", this.DeviceKind, this.DeviceName);
}
}
}
diff --git a/dotnet/src/webdriver/Interactions/KeyInputDevice.cs b/dotnet/src/webdriver/Interactions/KeyInputDevice.cs
index 4273a59b6c0c0..d04a05e3866b4 100644
--- a/dotnet/src/webdriver/Interactions/KeyInputDevice.cs
+++ b/dotnet/src/webdriver/Interactions/KeyInputDevice.cs
@@ -21,6 +21,8 @@
using System.Collections.Generic;
using System.Globalization;
+#nullable enable
+
namespace OpenQA.Selenium.Interactions
{
///
@@ -40,6 +42,7 @@ public KeyInputDevice()
/// Initializes a new instance of the class, given the device's name.
///
/// The unique name of this input device.
+ /// If is or .
public KeyInputDevice(string deviceName)
: base(deviceName)
{
@@ -48,10 +51,7 @@ public KeyInputDevice(string deviceName)
///
/// Gets the type of device for this input device.
///
- public override InputDeviceKind DeviceKind
- {
- get { return InputDeviceKind.Key; }
- }
+ public override InputDeviceKind DeviceKind => InputDeviceKind.Key;
///
/// Converts this input device into an object suitable for serializing across the wire.
@@ -115,27 +115,23 @@ public override string ToString()
private class TypingInteraction : Interaction
{
- private string type;
- private string value;
+ private readonly string type;
public TypingInteraction(InputDevice sourceDevice, string type, char codePoint)
: base(sourceDevice)
{
this.type = type;
- this.value = codePoint.ToString();
+ this.Value = codePoint.ToString();
}
- protected string Value
- {
- get { return this.value; }
- }
+ protected string Value { get; }
public override Dictionary ToDictionary()
{
Dictionary toReturn = new Dictionary();
toReturn["type"] = this.type;
- toReturn["value"] = this.value;
+ toReturn["value"] = this.Value;
return toReturn;
}
diff --git a/dotnet/src/webdriver/Interactions/PointerInputDevice.cs b/dotnet/src/webdriver/Interactions/PointerInputDevice.cs
index ef57abe4e49cb..ca92a7136b378 100644
--- a/dotnet/src/webdriver/Interactions/PointerInputDevice.cs
+++ b/dotnet/src/webdriver/Interactions/PointerInputDevice.cs
@@ -22,6 +22,8 @@
using System.Collections.Generic;
using System.Globalization;
+#nullable enable
+
namespace OpenQA.Selenium.Interactions
{
///
@@ -107,7 +109,7 @@ public enum MouseButton
///
public class PointerInputDevice : InputDevice
{
- private PointerKind pointerKind;
+ private readonly PointerKind pointerKind;
///
/// Initializes a new instance of the class.
@@ -131,6 +133,7 @@ public PointerInputDevice(PointerKind pointerKind)
///
/// The kind of pointer represented by this input device.
/// The unique name for this input device.
+ /// If is or .
public PointerInputDevice(PointerKind pointerKind, string deviceName)
: base(deviceName)
{
@@ -140,10 +143,7 @@ public PointerInputDevice(PointerKind pointerKind, string deviceName)
///
/// Gets the type of device for this input device.
///
- public override InputDeviceKind DeviceKind
- {
- get { return InputDeviceKind.Pointer; }
- }
+ public override InputDeviceKind DeviceKind => InputDeviceKind.Pointer;
///
/// Returns a value for this input device that can be transmitted across the wire to a remote end.
@@ -219,6 +219,7 @@ public Interaction CreatePointerUp(MouseButton button, PointerEventProperties pr
/// The vertical offset from the origin of the move.
/// The length of time the move gesture takes to complete.
/// The action representing the pointer move gesture.
+ /// If is .
public Interaction CreatePointerMove(IWebElement target, int xOffset, int yOffset, TimeSpan duration)
{
return CreatePointerMove(target, xOffset, yOffset, duration, new PointerEventProperties());
@@ -233,6 +234,7 @@ public Interaction CreatePointerMove(IWebElement target, int xOffset, int yOffse
/// The length of time the move gesture takes to complete.
/// The specifications for the pointer event interaction
/// The action representing the pointer move gesture.
+ /// If is .
public Interaction CreatePointerMove(IWebElement target, int xOffset, int yOffset, TimeSpan duration, PointerEventProperties properties)
{
return new PointerMoveInteraction(this, target, CoordinateOrigin.Element, xOffset, yOffset, duration, properties);
@@ -265,7 +267,7 @@ public Interaction CreatePointerMove(CoordinateOrigin origin, int xOffset, int y
/// The object containing additional proprties for this pointer move operation.
/// The action representing the pointer move gesture.
/// Thrown when passing CoordinateOrigin.Element into origin.
- /// Users should us the other CreatePointerMove overload to move to a specific element.
+ /// Users should use the other CreatePointerMove overload to move to a specific element.
public Interaction CreatePointerMove(CoordinateOrigin origin, int xOffset, int yOffset, TimeSpan duration, PointerEventProperties properties)
{
if (origin == CoordinateOrigin.Element)
@@ -290,44 +292,24 @@ public Interaction CreatePointerCancel()
///
public class PointerEventProperties
{
- private double? width;
- private double? height;
- private double? pressure;
- private double? tangentialPressure;
- private int? tiltX;
- private int? tiltY;
- private int? twist;
- private double? altitudeAngle;
- private double? azimuthAngle;
-
///
/// Gets or sets the width (magnitude on x-axis) in pixels of the contact geometry of the pointer.
///
- public double? Width
- {
- get { return this.width; }
- set { this.width = value; }
- }
+ public double? Width { get; set; }
///
/// Gets or sets the height (magnitude on y-axis) in pixels of the contact geometry of the pointer.
///
- public double? Height
- {
- get { return this.height; }
- set { this.height = value; }
- }
+ public double? Height { get; set; }
+
///
/// Gets or sets the normalized pressure of the pointer input.
///
///
/// 0 and 1 represent the minimum and maximum pressure the hardware is capable of detecting, respectively.
///
- public double? Pressure
- {
- get { return this.pressure; }
- set { this.pressure = value; }
- }
+ public double? Pressure { get; set; }
+
///
/// Gets or sets the normalized tangential pressure (also known as barrel pressure) of the pointer input.
///
@@ -335,11 +317,8 @@ public double? Pressure
/// Valid values are between -1 and 1 with 0 being the neutral position of the control.
/// Some hardware may only support positive values between 0 and 1.
///
- public double? TangentialPressure
- {
- get { return this.tangentialPressure; }
- set { this.tangentialPressure = value; }
- }
+ public double? TangentialPressure { get; set; }
+
///
/// Gets or sets the plane angle in degrees between the Y-Z plane and the plane containing
/// both the transducer (e.g. pen stylus) axis and the Y axis..
@@ -347,11 +326,8 @@ public double? TangentialPressure
///
/// Valid values are between -90 and 90. A positive value is to the right.
///
- public int? TiltX
- {
- get { return this.tiltX; }
- set { this.tiltX = value; }
- }
+ public int? TiltX { get; set; }
+
///
/// Gets or sets the plane angle in degrees between the X-Z plane and the plane containing
/// both the transducer (e.g. pen stylus) axis and the X axis..
@@ -359,22 +335,16 @@ public int? TiltX
///
/// Valid values are between -90 and 90. A positive value is toward the user.
///
- public int? TiltY
- {
- get { return this.tiltY; }
- set { this.tiltY = value; }
- }
+ public int? TiltY { get; set; }
+
///
/// Gets or sets the clockwise rotation in degrees of a transducer (e.g. stylus) around its own major axis
///
///
/// Valid values are between 0 and 359.
///
- public int? Twist
- {
- get { return this.twist; }
- set { this.twist = value; }
- }
+ public int? Twist { get; set; }
+
///
/// Gets or sets the altitude in radians of the transducer (e.g. pen/stylus)
///
@@ -382,11 +352,8 @@ public int? Twist
/// Valid values are between 0 and π/2, where 0 is parallel to the surface (X-Y plane),
/// and π/2 is perpendicular to the surface.
///
- public double? AltitudeAngle
- {
- get { return this.altitudeAngle; }
- set { this.altitudeAngle = value; }
- }
+ public double? AltitudeAngle { get; set; }
+
///
/// Gets or sets the azimuth angle (in radians) of the transducer (e.g. pen/stylus)
///
@@ -395,11 +362,7 @@ public double? AltitudeAngle
/// where 0 represents a transducer whose cap is pointing in the direction of increasing X values,
/// and the values progressively increase when going clockwise.
///
- public double? AzimuthAngle
- {
- get { return this.azimuthAngle; }
- set { this.azimuthAngle = value; }
- }
+ public double? AzimuthAngle { get; set; }
///
/// Serializes the properties of this input device as a dictionary.
@@ -414,44 +377,44 @@ public Dictionary ToDictionary()
toReturn["width"] = this.Width.Value;
}
- if (this.height.HasValue)
+ if (this.Height.HasValue)
{
- toReturn["height"] = this.height.Value;
+ toReturn["height"] = this.Height.Value;
}
- if (this.pressure.HasValue)
+ if (this.Pressure.HasValue)
{
- toReturn["pressure"] = this.pressure.Value;
+ toReturn["pressure"] = this.Pressure.Value;
}
- if (this.tangentialPressure.HasValue)
+ if (this.TangentialPressure.HasValue)
{
- toReturn["tangentialPressure"] = this.tangentialPressure.Value;
+ toReturn["tangentialPressure"] = this.TangentialPressure.Value;
}
- if (this.tiltX.HasValue)
+ if (this.TiltX.HasValue)
{
- toReturn["tiltX"] = this.tiltX.Value;
+ toReturn["tiltX"] = this.TiltX.Value;
}
- if (this.tiltY.HasValue)
+ if (this.TiltY.HasValue)
{
- toReturn["tiltY"] = this.tiltY.Value;
+ toReturn["tiltY"] = this.TiltY.Value;
}
- if (this.twist.HasValue)
+ if (this.Twist.HasValue)
{
- toReturn["twist"] = this.twist.Value;
+ toReturn["twist"] = this.Twist.Value;
}
- if (this.altitudeAngle.HasValue)
+ if (this.AltitudeAngle.HasValue)
{
- toReturn["altitudeAngle"] = this.altitudeAngle.Value;
+ toReturn["altitudeAngle"] = this.AltitudeAngle.Value;
}
- if (this.azimuthAngle.HasValue)
+ if (this.AzimuthAngle.HasValue)
{
- toReturn["azimuthAngle"] = this.azimuthAngle.Value;
+ toReturn["azimuthAngle"] = this.AzimuthAngle.Value;
}
return toReturn;
@@ -460,8 +423,8 @@ public Dictionary ToDictionary()
private class PointerDownInteraction : Interaction
{
- private MouseButton button;
- private PointerEventProperties eventProperties;
+ private readonly MouseButton button;
+ private readonly PointerEventProperties eventProperties;
public PointerDownInteraction(InputDevice sourceDevice, MouseButton button, PointerEventProperties properties)
: base(sourceDevice)
@@ -473,7 +436,7 @@ public PointerDownInteraction(InputDevice sourceDevice, MouseButton button, Poin
public override Dictionary ToDictionary()
{
Dictionary toReturn;
- if (eventProperties == null)
+ if (eventProperties is null)
{
toReturn = new Dictionary();
}
@@ -495,8 +458,8 @@ public override string ToString()
private class PointerUpInteraction : Interaction
{
- private MouseButton button;
- private PointerEventProperties eventProperties;
+ private readonly MouseButton button;
+ private readonly PointerEventProperties eventProperties;
public PointerUpInteraction(InputDevice sourceDevice, MouseButton button, PointerEventProperties properties)
: base(sourceDevice)
@@ -508,7 +471,7 @@ public PointerUpInteraction(InputDevice sourceDevice, MouseButton button, Pointe
public override Dictionary ToDictionary()
{
Dictionary toReturn;
- if (eventProperties == null)
+ if (eventProperties is null)
{
toReturn = new Dictionary();
}
@@ -551,14 +514,14 @@ public override string ToString()
private class PointerMoveInteraction : Interaction
{
- private IWebElement target;
- private int x = 0;
- private int y = 0;
+ private readonly IWebElement? target;
+ private readonly int x = 0;
+ private readonly int y = 0;
private TimeSpan duration = TimeSpan.MinValue;
- private CoordinateOrigin origin = CoordinateOrigin.Pointer;
- private PointerEventProperties eventProperties;
+ private readonly CoordinateOrigin origin = CoordinateOrigin.Pointer;
+ private readonly PointerEventProperties eventProperties;
- public PointerMoveInteraction(InputDevice sourceDevice, IWebElement target, CoordinateOrigin origin, int x, int y, TimeSpan duration, PointerEventProperties properties)
+ public PointerMoveInteraction(InputDevice sourceDevice, IWebElement? target, CoordinateOrigin origin, int x, int y, TimeSpan duration, PointerEventProperties properties)
: base(sourceDevice)
{
if (target != null)
@@ -622,7 +585,7 @@ public override string ToString()
string originDescription = this.origin.ToString();
if (this.origin == CoordinateOrigin.Element)
{
- originDescription = this.target.ToString();
+ originDescription = this.target?.ToString() ?? "";
}
return string.Format(CultureInfo.InvariantCulture, "Pointer move [origin: {0}, x offset: {1}, y offset: {2}, duration: {3}ms]", originDescription, this.x, this.y, this.duration.TotalMilliseconds);
@@ -630,10 +593,10 @@ public override string ToString()
private Dictionary ConvertElement()
{
- IWebDriverObjectReference elementReference = this.target as IWebDriverObjectReference;
+ IWebDriverObjectReference? elementReference = this.target as IWebDriverObjectReference;
if (elementReference == null)
{
- IWrapsElement elementWrapper = this.target as IWrapsElement;
+ IWrapsElement? elementWrapper = this.target as IWrapsElement;
if (elementWrapper != null)
{
elementReference = elementWrapper.WrappedElement as IWebDriverObjectReference;
diff --git a/dotnet/src/webdriver/Interactions/WheelInputDevice.cs b/dotnet/src/webdriver/Interactions/WheelInputDevice.cs
index 2016d229a08c2..8d690ba4c7db6 100644
--- a/dotnet/src/webdriver/Interactions/WheelInputDevice.cs
+++ b/dotnet/src/webdriver/Interactions/WheelInputDevice.cs
@@ -21,6 +21,8 @@
using System;
using System.Collections.Generic;
+#nullable enable
+
namespace OpenQA.Selenium.Interactions
{
///
@@ -40,6 +42,7 @@ public WheelInputDevice()
/// Initializes a new instance of the class, given the device's name.
///
/// The unique name of this input device.
+ /// If is or .
public WheelInputDevice(string deviceName)
: base(deviceName)
{
@@ -48,10 +51,7 @@ public WheelInputDevice(string deviceName)
///
/// Gets the type of device for this input device.
///
- public override InputDeviceKind DeviceKind
- {
- get { return InputDeviceKind.Wheel; }
- }
+ public override InputDeviceKind DeviceKind => InputDeviceKind.Wheel;
///
/// Returns a value for this input device that can be transmitted across the wire to a remote end.
@@ -89,8 +89,14 @@ public Interaction CreateWheelScroll(int deltaX, int deltaY, TimeSpan duration)
/// The distance along the Y axis to scroll using the wheel.
/// The duration of the scroll action.
/// The representing the wheel scroll.
+ /// If is .
public Interaction CreateWheelScroll(IWebElement target, int xOffset, int yOffset, int deltaX, int deltaY, TimeSpan duration)
{
+ if (target is null)
+ {
+ throw new ArgumentNullException(nameof(target));
+ }
+
return new WheelScrollInteraction(this, target, CoordinateOrigin.Element, xOffset, yOffset, deltaX, deltaY, duration);
}
@@ -114,60 +120,39 @@ public Interaction CreateWheelScroll(CoordinateOrigin origin, int xOffset, int y
///
public class ScrollOrigin
{
- private IWebElement element;
- private bool viewport;
- private int xOffset = 0;
- private int yOffset = 0;
-
///
/// Gets or sets the element for the scroll origin.
///
- public IWebElement Element
- {
- get { return this.element; }
- set { this.element = value; }
- }
+ public IWebElement? Element { get; set; }
///
/// Gets or sets a value indicating whether the viewport should be used as the origin.
///
- public bool Viewport
- {
- get { return this.viewport; }
- set { this.viewport = value; }
- }
+ public bool Viewport { get; set; }
///
/// Gets or sets the horizontal offset of the scroll origin.
///
- public int XOffset
- {
- get { return this.xOffset; }
- set { this.xOffset = value; }
- }
+ public int XOffset { get; set; } = 0;
///
/// Gets or sets the vertical offset of the scroll origin.
///
- public int YOffset
- {
- get { return this.yOffset; }
- set { this.yOffset = value; }
- }
+ public int YOffset { get; set; } = 0;
}
private class WheelScrollInteraction : Interaction
{
- private IWebElement target;
- private int x = 0;
- private int y = 0;
- private int deltaX = 0;
- private int deltaY = 0;
- private TimeSpan duration = TimeSpan.MinValue;
- private CoordinateOrigin origin = CoordinateOrigin.Viewport;
-
- public WheelScrollInteraction(InputDevice sourceDevice, IWebElement target, CoordinateOrigin origin, int x, int y, int deltaX, int deltaY, TimeSpan duration)
+ private readonly IWebElement? target;
+ private readonly int x = 0;
+ private readonly int y = 0;
+ private readonly int deltaX = 0;
+ private readonly int deltaY = 0;
+ private readonly TimeSpan duration = TimeSpan.MinValue;
+ private readonly CoordinateOrigin origin = CoordinateOrigin.Viewport;
+
+ public WheelScrollInteraction(InputDevice sourceDevice, IWebElement? target, CoordinateOrigin origin, int x, int y, int deltaX, int deltaY, TimeSpan duration)
: base(sourceDevice)
{
if (target != null)
@@ -224,10 +209,10 @@ public override Dictionary ToDictionary()
private Dictionary ConvertElement()
{
- IWebDriverObjectReference elementReference = this.target as IWebDriverObjectReference;
+ IWebDriverObjectReference? elementReference = this.target as IWebDriverObjectReference;
if (elementReference == null)
{
- IWrapsElement elementWrapper = this.target as IWrapsElement;
+ IWrapsElement? elementWrapper = this.target as IWrapsElement;
if (elementWrapper != null)
{
elementReference = elementWrapper.WrappedElement as IWebDriverObjectReference;