Skip to content

Commit 650aa74

Browse files
committed
Support for hover over image or location
In Sikuli, sometimes clicks does not work in Graphics Area, the solution for this is to first hover, wait and then click as specified here RaiMan/SikuliX-2014#260 So adding support for hover command
1 parent 7b2adab commit 650aa74

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

SikuliSharp.Tests/EndToEndTests.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ public void CanRunSikuliCommands()
4949

5050
Assert.That(session.Exists(greenLabelPattern), Is.False, "Green label should not exist yet");
5151

52-
Assert.That(session.Click(testButtonPattern), Is.True, "Click on test button");
52+
Assert.That(session.Hover(testButtonPattern), Is.True, "Hover over Test Button");
53+
54+
Assert.That(session.Hover(new Location(appLocation.X + 350, appLocation.Y + 100)), Is.True, "Hover outside Test Button");
55+
56+
Assert.That(session.Click(testButtonPattern), Is.True, "Click on test button");
5357

5458
Assert.That(session.Exists(greenLabelPattern), Is.False, "Green label should still not exist (a 5s timer is shown)");
5559

SikuliSharp.Tests/Unit/SikuliSessionTests.cs

+17-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,21 @@ public IEnumerable<CommandTestData> CommandsTestSource
6363
// ReSharper disable once RedundantArgumentDefaultValue
6464
Method = (session, pattern) => session.WaitVanish(pattern, 0f)
6565
};
66-
}
66+
67+
yield return new CommandTestData
68+
{
69+
Timeout = 0f,
70+
ExpectedCommand = "print \"SIKULI#: YES\" if hover(::PATTERN::) else \"SIKULI#: NO\"",
71+
Method = (session, pattern) => session.Hover(pattern)
72+
};
73+
74+
yield return new CommandTestData
75+
{
76+
Timeout = 0f,
77+
ExpectedCommand = "print \"SIKULI#: YES\" if hover(::PATTERN::.targetOffset(0, -100)) else \"SIKULI#: NO\"",
78+
Method = (session, pattern) => session.Hover(pattern, new Point(0, -100))
79+
};
80+
}
6781
}
6882

6983
[SetUp]
@@ -134,8 +148,8 @@ public IEnumerable<string> InvalidTypeTestSource
134148
}
135149
}
136150

137-
[Test, TestCaseSource("InvalidTypeTestSource"), ExpectedException(typeof(ArgumentException))]
138-
public void TypeWithInvalidTextThrows(string text)
151+
[Test, TestCaseSource("InvalidTypeTestSource"), ExpectedException(typeof(ArgumentException))]
152+
public void TypeWithInvalidTextThrows(string text)
139153
{
140154
_session.Type(text);
141155
}

SikuliSharp/SikuliSession.cs

+15-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public interface ISikuliSession : IDisposable
1313
bool Wait(IPattern pattern, float timeoutInSeconds = 0);
1414
bool WaitVanish(IPattern pattern, float timeoutInSeconds = 0);
1515
bool Type(string text);
16-
}
16+
bool Hover(IPattern pattern);
17+
bool Hover(IPattern pattern, Point offset);
18+
}
1719

1820
public class SikuliSession : ISikuliSession
1921
{
@@ -75,7 +77,17 @@ public bool Type(string text)
7577
return result.Contains("SIKULI#: YES");
7678
}
7779

78-
protected bool RunCommand(string command, IPattern pattern, float commandParameter)
80+
public bool Hover(IPattern pattern)
81+
{
82+
return RunCommand("hover", pattern, 0);
83+
}
84+
85+
public bool Hover(IPattern pattern, Point offset)
86+
{
87+
return RunCommand("hover", new WithOffsetPattern(pattern, offset), 0);
88+
}
89+
90+
protected bool RunCommand(string command, IPattern pattern, float commandParameter)
7991
{
8092
pattern.Validate();
8193

@@ -98,8 +110,6 @@ private static string ToSukuliFloat(float timeoutInSeconds)
98110
public void Dispose()
99111
{
100112
_runtime.Stop();
101-
}
102-
103-
113+
}
104114
}
105115
}

0 commit comments

Comments
 (0)