javascriptintellij-ideaautomated-testssikulisikuli-script

How do I write a test in JavaScript using the Sikuli library?


I am looking to drive a macOS application like Calculator. I have pulled down the Sikuli jar file from Maven. I have watched the Joe C. video on this using Java and Eclipse. I am looking to do this in IntelliJ and to use JavaScript instead.

This will allow me to use my preferred IDE instead of a non-industry standard IDE like SikuliX.


Solution

  • This is the solution that I wrote using JavaScript and the Sikuli Script jar file available on SonaType.

    var imports = new JavaImporter(java.io, java.lang, org.sikuli.script, org.sikuli.natives, org.junit);
    with (imports) {
        var path = "/Users/dave/IdeaProjects/Sikuli/images/";
        var eight = path + "eight.png";
        var multiply = path + "multiply.png";
        var five = path + "five.png";
        var three = path + "three.png";
        var equals = path + "equals.png";
        var result = path + "result.png";
    
        var Screen = Java.type("org.sikuli.script.Screen");
        var App = Java.type("org.sikuli.script.App");
        var MacUtil = Java.type("org.sikuli.natives.MacUtil");
        var Assert = Java.type("org.junit.Assert");
    
        var s = new Screen();
        var a = new App();
        var mu = new MacUtil();
    
        a.setName("Calculator");
    
        mu.open(a);
    
        s.click(eight);
        s.click(multiply);
        s.click(three);
        s.click(equals);
        Assert.assertNotNull("The Image is not Correct", s.exists(result));
    }