Skip to content

[dotnet]: Remove ActionBuilder type and Create{InputDevice}{Action} methods #14873

@RenderMichael

Description

@RenderMichael

Feature and motivation

Currently, users can perform high-level custom operations with the Actions class, as such:

var actions = new Actions(driver);

actions
    .KeyDown(Keys.Control)
    .Click(driver.FindElement(By.Id("target")))
    .KeyUp(Keys.Control)
    .Perform();

The underlying mechanism is the ActionBuilder, which is used by Actions like so:

this.actionBuilder.AddAction(this.GetActivePointer().CreatePointerMove(element, 0, 0, duration));
this.actionBuilder.AddAction(this.GetActivePointer().CreatePointerDown(MouseButton.Left));
this.actionBuilder.AddAction(this.GetActivePointer().CreatePointerUp(MouseButton.Left));

ActionBuilder is a publicly-exposed type. However, there is no way to use it directly - the builder on the Actions type is private, and there is no way to add arbitrary Interactions to the Actions class either.

Proposal

public class Actions
{
+     public void AddAction(Interaction interaction)
}

Alternative proposal 1

Alternatively, users could be able to make their own set of actions directly on the ActionBuilder and pass that to an Actions to execute.

public class Actions
{
+ public Actions(IWebDriver driver, ActionBuilder builder)
}

However, this makes some operations harder because we no longer have access to GetActive{Pointer|Keyboard|Wheel} methods.

Alternative proposal 2

If we do not want users to be making their own interactions, and instead prefer to expose only higher-level operations directly on the Actions class, then we should not expose this functionality to users

- public class ActionBuilder
+ internal class ActionBuilder
public class KeyInputDevice
{
- public Interaction CreateKeyDown(char codePoint)
+ internal Interaction CreateKeyDown(char codePoint)

- public Interaction CreateKeyUp(char codePoint)
+ internal Interaction CreateKeyUp(char codePoint)
}
public class WheelInputDevice
{
- public Interaction CreateWheelScroll(int deltaX, int deltaY, TimeSpan duration)
+ internal Interaction CreateWheelScroll(int deltaX, int deltaY, TimeSpan duration)

- public Interaction CreateWheelScroll(IWebElement target, int xOffset, int yOffset, int deltaX, int deltaY, TimeSpan duration)
+ internal Interaction CreateWheelScroll(IWebElement target, int xOffset, int yOffset, int deltaX, int deltaY, TimeSpan duration)

- public Interaction CreateWheelScroll(CoordinateOrigin origin, int xOffset, int yOffset, int deltaX, int deltaY, TimeSpan duration)
+ internal Interaction CreateWheelScroll(CoordinateOrigin origin, int xOffset, int yOffset, int deltaX, int deltaY, TimeSpan duration)
}
public class PointerInputDevice
{
- public Interaction CreatePointerDown(MouseButton button)
+ internal Interaction CreatePointerDown(MouseButton button)

- public Interaction CreatePointerDown(MouseButton button, PointerEventProperties properties)
+ internal Interaction CreatePointerDown(MouseButton button, PointerEventProperties properties)

- public Interaction CreatePointerUp(MouseButton button)
+ internal Interaction CreatePointerUp(MouseButton button)

- public Interaction CreatePointerUp(MouseButton button, PointerEventProperties properties)
+ internal Interaction CreatePointerUp(MouseButton button, PointerEventProperties properties)

- public Interaction CreatePointerMove(IWebElement target, int xOffset, int yOffset, TimeSpan duration)
+ internal Interaction CreatePointerMove(IWebElement target, int xOffset, int yOffset, TimeSpan duration)

- public Interaction CreatePointerMove(IWebElement target, int xOffset, int yOffset, TimeSpan duration, PointerEventProperties 
properties)
+ internal Interaction CreatePointerMove(IWebElement target, int xOffset, int yOffset, TimeSpan duration, PointerEventProperties properties)

- public Interaction CreatePointerMove(CoordinateOrigin origin, int xOffset, int yOffset, TimeSpan duration)
+ internal Interaction CreatePointerMove(CoordinateOrigin origin, int xOffset, int yOffset, TimeSpan duration)

- public Interaction CreatePointerMove(CoordinateOrigin origin, int xOffset, int yOffset, TimeSpan duration, PointerEventProperties properties)
+ internal Interaction CreatePointerMove(CoordinateOrigin origin, int xOffset, int yOffset, TimeSpan duration, PointerEventProperties properties)

- public Interaction CreatePointerCancel()
+ internal Interaction CreatePointerCancel()
}

Usage example

With the above method, people will be able to add and invoke the entire currently-underutilized set of interactions one can make, such as this:

var actions = new Actions(driver);

var properties = new PointerInputDevice.PointerEventProperties()
{
    Width = 10,
    Height = 11,
    Pressure = 0.5,
    TangentialPressure = 0.1,
    TiltX = 15,
    TiltY = 15,
    Twist = 30,
    AltitudeAngle = 0.1,
    AzimuthAngle = 0.1
};

actions.AddAction(actions.GetActivePointer().CreatePointerDown(MouseButton.Left, properties));

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!C-dotnet.NET BindingsI-enhancementSomething could be better

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions