Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RenderMichael opened this issue Dec 8, 2024 · 1 comment

Comments

@RenderMichael
Copy link
Contributor

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));
Copy link

github-actions bot commented Dec 8, 2024

@RenderMichael, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant