Skip to content

Commit

Permalink
Support for hover over image or location
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mnkjadhav committed Dec 28, 2017
1 parent 7b2adab commit 650aa74
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
6 changes: 5 additions & 1 deletion SikuliSharp.Tests/EndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public void CanRunSikuliCommands()

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

Assert.That(session.Click(testButtonPattern), Is.True, "Click on test button");
Assert.That(session.Hover(testButtonPattern), Is.True, "Hover over Test Button");

Assert.That(session.Hover(new Location(appLocation.X + 350, appLocation.Y + 100)), Is.True, "Hover outside Test Button");

Assert.That(session.Click(testButtonPattern), Is.True, "Click on test button");

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

Expand Down
20 changes: 17 additions & 3 deletions SikuliSharp.Tests/Unit/SikuliSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,21 @@ public IEnumerable<CommandTestData> CommandsTestSource
// ReSharper disable once RedundantArgumentDefaultValue
Method = (session, pattern) => session.WaitVanish(pattern, 0f)
};
}

yield return new CommandTestData
{
Timeout = 0f,
ExpectedCommand = "print \"SIKULI#: YES\" if hover(::PATTERN::) else \"SIKULI#: NO\"",
Method = (session, pattern) => session.Hover(pattern)
};

yield return new CommandTestData
{
Timeout = 0f,
ExpectedCommand = "print \"SIKULI#: YES\" if hover(::PATTERN::.targetOffset(0, -100)) else \"SIKULI#: NO\"",
Method = (session, pattern) => session.Hover(pattern, new Point(0, -100))
};
}
}

[SetUp]
Expand Down Expand Up @@ -134,8 +148,8 @@ public IEnumerable<string> InvalidTypeTestSource
}
}

[Test, TestCaseSource("InvalidTypeTestSource"), ExpectedException(typeof(ArgumentException))]
public void TypeWithInvalidTextThrows(string text)
[Test, TestCaseSource("InvalidTypeTestSource"), ExpectedException(typeof(ArgumentException))]
public void TypeWithInvalidTextThrows(string text)
{
_session.Type(text);
}
Expand Down
20 changes: 15 additions & 5 deletions SikuliSharp/SikuliSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public interface ISikuliSession : IDisposable
bool Wait(IPattern pattern, float timeoutInSeconds = 0);
bool WaitVanish(IPattern pattern, float timeoutInSeconds = 0);
bool Type(string text);
}
bool Hover(IPattern pattern);
bool Hover(IPattern pattern, Point offset);
}

public class SikuliSession : ISikuliSession
{
Expand Down Expand Up @@ -75,7 +77,17 @@ public bool Type(string text)
return result.Contains("SIKULI#: YES");
}

protected bool RunCommand(string command, IPattern pattern, float commandParameter)
public bool Hover(IPattern pattern)
{
return RunCommand("hover", pattern, 0);
}

public bool Hover(IPattern pattern, Point offset)
{
return RunCommand("hover", new WithOffsetPattern(pattern, offset), 0);
}

protected bool RunCommand(string command, IPattern pattern, float commandParameter)
{
pattern.Validate();

Expand All @@ -98,8 +110,6 @@ private static string ToSukuliFloat(float timeoutInSeconds)
public void Dispose()
{
_runtime.Stop();
}


}
}
}

0 comments on commit 650aa74

Please sign in to comment.