-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathTouchLongPressExecutor.cs
More file actions
71 lines (58 loc) · 2.17 KB
/
Copy pathTouchLongPressExecutor.cs
File metadata and controls
71 lines (58 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
}
}