Skip to content

Commit

Permalink
Removing legacy OSS protocol dialect from .NET Actions class
Browse files Browse the repository at this point in the history
The Actions class now conducts all actions using the W3C Specification
compliant dialect of the wire protocol.
  • Loading branch information
jimevans committed Apr 11, 2019
1 parent 8767cd3 commit 422a4cf
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 761 deletions.
88 changes: 26 additions & 62 deletions dotnet/src/webdriver/Interactions/Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,46 +49,38 @@ public class Actions : IAction
private ActionBuilder actionBuilder = new ActionBuilder();
private PointerInputDevice defaultMouse = new PointerInputDevice(PointerKind.Mouse, "default mouse");
private KeyInputDevice defaultKeyboard = new KeyInputDevice("default keyboard");

private IKeyboard keyboard;
private IMouse mouse;
private IActionExecutor actionExecutor;
private CompositeAction action = new CompositeAction();

/// <summary>
/// Initializes a new instance of the <see cref="Actions"/> class.
/// </summary>
/// <param name="driver">The <see cref="IWebDriver"/> object on which the actions built will be performed.</param>
public Actions(IWebDriver driver)
{
//this.driver = driver;
IHasInputDevices inputDevicesDriver = GetDriverAs<IHasInputDevices>(driver);
if (inputDevicesDriver == null)
{
throw new ArgumentException("The IWebDriver object must implement or wrap a driver that implements IHasInputDevices.", "driver");
}

IActionExecutor actionExecutor = GetDriverAs<IActionExecutor>(driver);
if (actionExecutor == null)
{
throw new ArgumentException("The IWebDriver object must implement or wrap a driver that implements IActionExecutor.", "driver");
}

this.keyboard = inputDevicesDriver.Keyboard;
this.mouse = inputDevicesDriver.Mouse;
this.actionExecutor = actionExecutor;
}

/// <summary>
/// Sends a modifier key down message to the browser.
/// </summary>
/// <param name="theKey">The key to be sent.</param>
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
/// <exception cref="ArgumentException">If the key sent is not is not one
/// of <see cref="Keys.Shift"/>, <see cref="Keys.Control"/>, <see cref="Keys.Alt"/>,
/// <see cref="Keys.Meta"/>, <see cref="Keys.Command"/>,<see cref="Keys.LeftAlt"/>,
/// <see cref="Keys.LeftControl"/>,<see cref="Keys.LeftShift"/>.</exception>
public Actions KeyDown(string theKey)
protected IActionExecutor ActionExecutor
{
get { return this.actionExecutor; }
}

/// <summary>
/// Sends a modifier key down message to the browser.
/// </summary>
/// <param name="theKey">The key to be sent.</param>
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
/// <exception cref="ArgumentException">If the key sent is not is not one
/// of <see cref="Keys.Shift"/>, <see cref="Keys.Control"/>, <see cref="Keys.Alt"/>,
/// <see cref="Keys.Meta"/>, <see cref="Keys.Command"/>,<see cref="Keys.LeftAlt"/>,
/// <see cref="Keys.LeftControl"/>,<see cref="Keys.LeftShift"/>.</exception>
public Actions KeyDown(string theKey)
{
return this.KeyDown(null, theKey);
}
Expand All @@ -111,7 +103,6 @@ public Actions KeyDown(IWebElement element, string theKey)
}

ILocatable target = GetLocatableFromElement(element);
this.action.AddAction(new KeyDownAction(this.keyboard, this.mouse, target, theKey));
if (element != null)
{
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerMove(element, 0, 0, DefaultMouseMoveDuration));
Expand All @@ -124,16 +115,16 @@ public Actions KeyDown(IWebElement element, string theKey)
return this;
}

/// <summary>
/// Sends a modifier key up message to the browser.
/// </summary>
/// <param name="theKey">The key to be sent.</param>
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
/// <exception cref="ArgumentException">If the key sent is not is not one
/// of <see cref="Keys.Shift"/>, <see cref="Keys.Control"/>, <see cref="Keys.Alt"/>,
/// <see cref="Keys.Meta"/>, <see cref="Keys.Command"/>,<see cref="Keys.LeftAlt"/>,
/// <see cref="Keys.LeftControl"/>,<see cref="Keys.LeftShift"/>.</exception>
public Actions KeyUp(string theKey)
/// <summary>
/// Sends a modifier key up message to the browser.
/// </summary>
/// <param name="theKey">The key to be sent.</param>
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
/// <exception cref="ArgumentException">If the key sent is not is not one
/// of <see cref="Keys.Shift"/>, <see cref="Keys.Control"/>, <see cref="Keys.Alt"/>,
/// <see cref="Keys.Meta"/>, <see cref="Keys.Command"/>,<see cref="Keys.LeftAlt"/>,
/// <see cref="Keys.LeftControl"/>,<see cref="Keys.LeftShift"/>.</exception>
public Actions KeyUp(string theKey)
{
return this.KeyUp(null, theKey);
}
Expand All @@ -156,7 +147,6 @@ public Actions KeyUp(IWebElement element, string theKey)
}

ILocatable target = GetLocatableFromElement(element);
this.action.AddAction(new KeyUpAction(this.keyboard, this.mouse, target, theKey));
if (element != null)
{
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerMove(element, 0, 0, DefaultMouseMoveDuration));
Expand Down Expand Up @@ -192,7 +182,6 @@ public Actions SendKeys(IWebElement element, string keysToSend)
}

ILocatable target = GetLocatableFromElement(element);
this.action.AddAction(new SendKeysAction(this.keyboard, this.mouse, target, keysToSend));
if (element != null)
{
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerMove(element, 0, 0, DefaultMouseMoveDuration));
Expand Down Expand Up @@ -226,7 +215,6 @@ public Actions ClickAndHold(IWebElement onElement)
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
public Actions ClickAndHold()
{
this.action.AddAction(new ClickAndHoldAction(this.mouse, null));
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerDown(MouseButton.Left));
return this;
}
Expand All @@ -248,7 +236,6 @@ public Actions Release(IWebElement onElement)
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
public Actions Release()
{
this.action.AddAction(new ButtonReleaseAction(this.mouse, null));
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerUp(MouseButton.Left));
return this;
}
Expand All @@ -270,7 +257,6 @@ public Actions Click(IWebElement onElement)
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
public Actions Click()
{
this.action.AddAction(new ClickAction(this.mouse, null));
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerDown(MouseButton.Left));
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerUp(MouseButton.Left));
return this;
Expand All @@ -293,7 +279,6 @@ public Actions DoubleClick(IWebElement onElement)
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
public Actions DoubleClick()
{
this.action.AddAction(new DoubleClickAction(this.mouse, null));
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerDown(MouseButton.Left));
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerUp(MouseButton.Left));
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerDown(MouseButton.Left));
Expand All @@ -314,7 +299,6 @@ public Actions MoveToElement(IWebElement toElement)
}

ILocatable target = GetLocatableFromElement(toElement);
this.action.AddAction(new MoveMouseAction(this.mouse, target));
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerMove(toElement, 0, 0, DefaultMouseMoveDuration));
return this;
}
Expand Down Expand Up @@ -348,14 +332,12 @@ public Actions MoveToElement(IWebElement toElement, int offsetX, int offsetY, Mo
{
int modifiedOffsetX = offsetX - (elementSize.Width / 2);
int modifiedOffsetY = offsetY - (elementSize.Height / 2);
this.action.AddAction(new MoveToOffsetAction(this.mouse, target, offsetX, offsetY));
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerMove(toElement, modifiedOffsetX, modifiedOffsetY, DefaultMouseMoveDuration));
}
else
{
int modifiedOffsetX = offsetX + (elementSize.Width / 2);
int modifiedOffsetY = offsetY + (elementSize.Height / 2);
this.action.AddAction(new MoveToOffsetAction(this.mouse, target, modifiedOffsetX, modifiedOffsetY));
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerMove(toElement, offsetX, offsetY, DefaultMouseMoveDuration));
}
return this;
Expand All @@ -369,7 +351,6 @@ public Actions MoveToElement(IWebElement toElement, int offsetX, int offsetY, Mo
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
public Actions MoveByOffset(int offsetX, int offsetY)
{
this.action.AddAction(new MoveToOffsetAction(this.mouse, null, offsetX, offsetY));
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerMove(CoordinateOrigin.Pointer, offsetX, offsetY, DefaultMouseMoveDuration));
return this;
}
Expand All @@ -391,7 +372,6 @@ public Actions ContextClick(IWebElement onElement)
/// <returns>A self-reference to this <see cref="Actions"/>.</returns>
public Actions ContextClick()
{
this.action.AddAction(new ContextClickAction(this.mouse, null));
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerDown(MouseButton.Right));
this.actionBuilder.AddAction(this.defaultMouse.CreatePointerUp(MouseButton.Right));
return this;
Expand Down Expand Up @@ -436,14 +416,7 @@ public IAction Build()
/// </summary>
public void Perform()
{
if (this.actionExecutor.IsActionExecutor)
{
this.actionExecutor.PerformActions(this.actionBuilder.ToActionSequenceList());
}
else
{
this.action.Perform();
}
this.actionExecutor.PerformActions(this.actionBuilder.ToActionSequenceList());
}

/// <summary>
Expand Down Expand Up @@ -479,15 +452,6 @@ protected static ILocatable GetLocatableFromElement(IWebElement element)
return target;
}

/// <summary>
/// Adds an action to current list of actions to be performed.
/// </summary>
/// <param name="actionToAdd">The <see cref="IAction"/> to be added.</param>
protected void AddAction(IAction actionToAdd)
{
this.action.AddAction(actionToAdd);
}

private T GetDriverAs<T>(IWebDriver driver) where T : class
{
T driverAsType = driver as T;
Expand Down
55 changes: 0 additions & 55 deletions dotnet/src/webdriver/Interactions/ButtonReleaseAction.cs

This file was deleted.

47 changes: 0 additions & 47 deletions dotnet/src/webdriver/Interactions/ClickAction.cs

This file was deleted.

47 changes: 0 additions & 47 deletions dotnet/src/webdriver/Interactions/ClickAndHoldAction.cs

This file was deleted.

0 comments on commit 422a4cf

Please sign in to comment.