Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Winium.Desktop.Driver.CommandExecutors
{
#region using

using System.Collections.Generic;

using Winium.StoreApps.Common;

#endregion

internal class GetElementLocationExecutor : CommandExecutorBase
{
#region Methods

protected override string DoImpl()
{
var registeredKey = this.ExecutedCommand.Parameters["ID"].ToString();

var element = this.Automator.ElementsRegistry.GetRegisteredElement(registeredKey);

var boundingRect = element.Properties.BoundingRectangle;

var response = new Dictionary<string, object>
{
{ "x", boundingRect.X },
{ "y", boundingRect.Y }
};
return this.JsonResponse(ResponseStatus.Success, response);
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Winium.Desktop.Driver.CommandExecutors
{
#region using

using Winium.Cruciatus.Core;
using Winium.StoreApps.Common;

#endregion

internal class TouchDoubleTapExecutor : CommandExecutorBase
{
#region Methods

protected override string DoImpl()
{
if (!this.ExecutedCommand.Parameters.ContainsKey("element"))
{
// TODO: in the future '400 : invalid argument' will be used
return this.JsonResponse(ResponseStatus.UnknownError, "WRONG PARAMETERS");
}

var registeredKey = this.ExecutedCommand.Parameters["element"].ToString();
var element = this.Automator.ElementsRegistry.GetRegisteredElement(registeredKey);

return TouchSimulator.DoubleTap(element)
? this.JsonResponse()
: this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed");
}

#endregion
}
}
74 changes: 74 additions & 0 deletions src/Winium.Desktop.Driver/CommandExecutors/TouchFlickExecutor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
namespace Winium.Desktop.Driver.CommandExecutors
{
#region using

using System;
using System.Threading;
using System.Windows;

using Winium.Cruciatus;
using Winium.Cruciatus.Core;
using Winium.Desktop.Driver.Extensions;
using Winium.StoreApps.Common;

#endregion

internal class TouchFlickExecutor : CommandExecutorBase
{
#region Methods

protected override string DoImpl()
{
if (this.ExecutedCommand.Parameters.ContainsKey("element"))
{
return FlickElement();
}

return Flick();
}

string Flick()
{
if (!(this.ExecutedCommand.Parameters.ContainsKey("xspeed")
&& this.ExecutedCommand.Parameters.ContainsKey("yspeed")))
{
// TODO: in the future '400 : invalid argument' will be used
return this.JsonResponse(ResponseStatus.UnknownError, "WRONG PARAMETERS");
}

var xSpeed = this.ExecutedCommand.GetParameterAsInt("xspeed");
var ySpeed = this.ExecutedCommand.GetParameterAsInt("yspeed");

return TouchSimulator.Flick(xSpeed, ySpeed)
? this.JsonResponse()
: this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed");
}

string FlickElement()
{
if (
!(this.ExecutedCommand.Parameters.ContainsKey("element")
&& this.ExecutedCommand.Parameters.ContainsKey("xoffset")
&& this.ExecutedCommand.Parameters.ContainsKey("yoffset")
&& this.ExecutedCommand.Parameters.ContainsKey("speed")))
{
// TODO: in the future '400 : invalid argument' will be used
return this.JsonResponse(ResponseStatus.UnknownError, "WRONG PARAMETERS");
}

var registeredKey = this.ExecutedCommand.Parameters["element"].ToString();
var element = this.Automator.ElementsRegistry.GetRegisteredElement(registeredKey);

var xOffset = this.ExecutedCommand.GetParameterAsInt("xoffset");
var yOffset = this.ExecutedCommand.GetParameterAsInt("yoffset");

var pixelsPerSecond = this.ExecutedCommand.GetParameterAsInt("speed");

return TouchSimulator.FlickElement(element, xOffset, yOffset, pixelsPerSecond)
? this.JsonResponse()
: this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed");
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
namespace Winium.Desktop.Driver.CommandExecutors
{
#region using

using System;

using Winium.Cruciatus.Core;
using Winium.Cruciatus.Elements;
using Winium.Desktop.Driver.Extensions;
using Winium.StoreApps.Common;

#endregion

internal class TouchLongPressExecutor : CommandExecutorBase
{
#region Methods

protected override string DoImpl()
{
var haveElement = this.ExecutedCommand.Parameters.ContainsKey("element");
var havePoint = this.ExecutedCommand.Parameters.ContainsKey("x")
&& this.ExecutedCommand.Parameters.ContainsKey("y");

if (!(haveElement || havePoint))
{
// TODO: in the future '400 : invalid argument' will be used
return this.JsonResponse(ResponseStatus.UnknownError, "WRONG PARAMETERS");
}

bool success;
CruciatusElement element = null;
var x = 0;
var y = 0;

if (haveElement)
{
var registeredKey = this.ExecutedCommand.Parameters["element"].ToString();
element = this.Automator.ElementsRegistry.GetRegisteredElement(registeredKey);
}

if (havePoint)
{
x = this.ExecutedCommand.GetParameterAsInt("x");
y = this.ExecutedCommand.GetParameterAsInt("y");
}

var duration = this.ExecutedCommand.Parameters.ContainsKey("duration")
? this.ExecutedCommand.GetParameterAsInt("duration")
: 1000;

if (haveElement && havePoint)
{
success = TouchSimulator.LongTap(element, x, y, duration);
}
else if (haveElement)
{
success = TouchSimulator.LongTap(element, duration);
}
else
{
success = TouchSimulator.LongTap(x, y, duration);
}

return success
? this.JsonResponse()
: this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed");
}

#endregion
}
}
50 changes: 50 additions & 0 deletions src/Winium.Desktop.Driver/CommandExecutors/TouchMoveExecutor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace Winium.Desktop.Driver.CommandExecutors
{
#region using

using System;

using Winium.Cruciatus.Core;
using Winium.Desktop.Driver.Extensions;
using Winium.StoreApps.Common;

#endregion

internal class TouchMoveExecutor : CommandExecutorBase
{
#region Methods

protected override string DoImpl()
{
if (!this.ExecutedCommand.Parameters.ContainsKey("x")
&& this.ExecutedCommand.Parameters.ContainsKey("y"))
{
// TODO: in the future '400 : invalid argument' will be used
return this.JsonResponse(ResponseStatus.UnknownError, "WRONG PARAMETERS");
}

var x = this.ExecutedCommand.GetParameterAsInt("x");
var y = this.ExecutedCommand.GetParameterAsInt("y");

bool success;

if (this.ExecutedCommand.Parameters.ContainsKey("element"))
{
var registeredKey = this.ExecutedCommand.Parameters["element"].ToString();
var element = this.Automator.ElementsRegistry.GetRegisteredElement(registeredKey);

success = TouchSimulator.TouchUpdate(element, x, y);
}
else
{
success = TouchSimulator.TouchUpdate(x, y);
}

return success
? this.JsonResponse()
: this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed");
}

#endregion
}
}
Loading