Test Automation on a JAVA AWT application? Have you ever tried this? Is this even possible? These were the questions I was asking myself a few months ago when the company I work for privileged me to do a feasibility study-like project. I’ve had prior experience in automating an application in a not-too-different but also not-too-similar technology with IBM’s Rational Functional Tester. Obviously this was the tool I was pushing for but life doesn’t always give you lemons. So I had to find a way to make lemonade with apples. Needless to say, about over a month later I found something that worked! Sikuli.
So Sikuli is an open source automation script that uses image recognition to identify and perform actions on GUI components. Basically when you create your automation script, instead of finding object properties in firebug you take a screenshot of it and call it in your code. Simple. My problem was Sikuli is only supported in eclipse and netbeans and my apple was the beast known as Visual Studio. Luckily there are some very smart and helpful people like the guy who created the SikuliSharp wrapper that you can use with Visual Studio so people like me and you can have an easier life. Anyway… here is how you integrate Sikulisharp with Visual Studio and how to create a simple login script in C#.
In MS VS 2015, Tools > NuGet Package Manager > Manage NuGet Packages for Solution..
Under Browse tab, enter “Sikuli” into the search box.
Click on your project in the right hand panel and click install.
If this dialog prompts, Click OK.
You’ll get an installation confirmation in the output view for Package Manager.
Validate SikuliSharp installation file in references folder of Solution Explorer
So now that you’ve done installing SikuliSharp, you’ll be needing the original Sikuli.
- Install Java
- Download and Install Sikuli
- Follow instructions in Sikuli page. http://www.sikulix.com/quickstart.html
- Choose option ‘to run scripts from the command line – the file sikuli-scripts.jar must be installed’
- Create an environment variable SIKULI_HOME that points to the folder where you installed Sikuli.
This is how to set an environment variable in step 3.
Go to Start > Right click on my computer > Properties
Click Advanced System Settings
Click Environment Variables
Under the system variable of the Environment variables window, click new and type in ‘SIKULI_HOME’ and the Sikuli installation path in the variable name and value fields, respectively. Click OK
Viola! Now you can start creating your automation test scripts.
You will need to import “using SikuliSharp;” in your unit tests to use the Sikuli methods.
Sample automation script:
using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using SikuliSharp; namespace SikuliTest { [TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { using (var session = Sikuli.CreateSession()) { //Login var username = Patterns.FromFile("Path\username.PNG", 0.9f); var password = Patterns.FromFile("Path\password.PNG", 0.9f); var submit = Patterns.FromFile("Path\submit.PNG", 0.9f); session.Click(username); session.Type("myUserName"); session.Click(password); session.Type("myPassword"); session.Click(submit); } } } }
For more reading:
https://github.com/christianrondeau/SikuliSharp
http://www.sikulix.com
Hello, I’ve VS2015, and Sikuli 1.1.0. My scripts run fine with Sikuli IDE, but no way to maje it work with VS2015 and Sikuli Sharp. Is it OK with Sikuli 1.10 ?
Thanks
LikeLike
You will need to manually convert your scripts using sikulisharp functions in VS or use the Sikuli.RunProject() function which you can read more about here: https://github.com/christianrondeau/SikuliSharp
LikeLike
Hi Philip,
can you tell me please, if is possible to do a double click with SikuliSharp?
Thanks
LikeLike
You may need to use a runtime jython console command like below.
using(var runtime = Sikuli.CreateRuntime())
{
runtime.Start();
var result = runtime.Run(
@”print “”RESULT: OK”” if doubleClick(“”C:\\Patterns\\MyPattern.png””) else “”RESULT: FAIL”””,
“RESULT:”,
0d
);
Assert.That(result, Is.StringContaining(“RESULT: OK”));
}
You can also contact the owner at
https://github.com/christianrondeau/SikuliSharp for more info.
LikeLike