-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Description
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 Interaction
s 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));