What is sikuli
Sikuli is a open source automation tool which is used to automate webelement of web application and window based pop up.
To integrate sikuli with selenium download and install sikuli in your local machine
To download and install sikuli follow the below steps:
->Go to google
->Search for “Sikuli download”
->Click on the link “https://launchpad.net/sikuli/+download”
->Download the latest sikuli setup jar file “sikulixsetup-1.1.3.jar (md5)”.
->Double click on setup file for installation.
->After completing installation you will get a jar file “Sikulixapi”.
->Add the jar file to the project by
Go to properties->java build path->Add external jar->Select the path of “sikulixapi” jar file->click on apply button.
Below example is to automate windows based calculator operations. Sikuli identify windows elements by identifying calculator , buttons we are performing multiplication here.
Code to automate calculator
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 |
<span style="font-size: 16px;">import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.io.IOException; import org.sikuli.script.FindFailed; import org.sikuli.script.Key; import org.sikuli.script.Screen; public class Notepad { public static void main(String[] args) throws IOException, FindFailed, UnsupportedFlavorException, InterruptedException { // This will open calculator application Runtime.getRuntime().exec("path of calculator\\calc.exe"); Screen s = new Screen(); // Provide the image path of element on which you want to perform action s.click("C:\\Users\\sikuli1\\nine.png"); s.click("C:\\Users\\sikuli1\\multiply.png"); s.click("C:\\Users\\sikuli1\\eight.png"); s.click("C:\\Users\\sikuli1\\equalto.png"); // Copy the output to clipboard s.type("c", Key.CTRL); Thread.sleep(5000); Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable t = clip.getContents(DataFlavor.stringFlavor); String text = (String) t.getTransferData(DataFlavor.stringFlavor); System.out.println(text); int value = Integer.parseInt(text); int a = 8; int b = 9; int mul = a * b; // Verify output if (mul == value) { System.out.println("result is same"); } else { System.out.println("Result is not same"); } } } </span> |
After running above program you will get output like this
72
result is same