Friday, 24 October 2014

Sikuli Tutorial

  • Installing Eclipse Maven Plugin
  • Installing Apache Maven
  • Install Sikuli Script Jar in Maven Repository
  • Creating Sikuli Maven Project
  • Example program: Open a file in Widows Explorer
  • Executing Sikuli Maven Project from Command line
  • Selenium vs Sikuli
  • Integrating Sikuli With Selenium WebDriver

Installing Eclipse Maven Plugin

Step #1:
Open Eclipse, Go to Help   -> Install a new Software. Click on “Add” button and add the following URL.
 sikuili10.
Click on “OK” button.
Step #2:
Check All the check boxes listed, click “Next” and install the maven plugin.
(Click on image to enlarge)
 sikuili11

Installing Apache Maven

Step #1:
Download latest version of maven from here.
Step #2:
Extract the downloaded zip file and put it under somewhere in your machine.
Copy the bin folder path of Maven, and append the path in the environment variable.
(It requires JAVA_HOME variable in the environment variable. Please set JAVA_HOME variable in your environment)
Step #3:
Check whether maven installed correctly, Open command prompt and type “mvn -version”. It should return something like this,
(Click on image to enlarge)
 sikuli12
It indicates Maven successfully installed in your machine.

Install Sikuli Script Jar in Maven Repository

As I mentioned in part -1, we’ve already got sikuli-script.jar, next we need to install sikuli-script.jar in maven repository.
By using the following command we can install sikuli-script.jar in maven repository.
Mvn install: install-file -Dfile=D:\Jars\Sikuli-r930\win32\Sikuli-IDE\sikuli-script.jar -DgroupId=com.test.sikuli -DartifactId=sikuli -Dversion-1.0.1 -Dpackaging=jar
(Click on image to enlarge)
 sikuli13

Creating Sikuli Maven Project

Step #1:
Open Eclipse and create new Maven Project.
Step #2:
Add the following dependencies in your POM file.
1<dependency>
2<groupId>com.test.sikuli</groupId>
3<artifactId>sikuli</artifactId>
4<version>1.0.1</version>
5</dependency>
6<dependency>
7<groupId>junit</groupId>
8<artifactId>junit</artifactId>
9<version>4.11</version>
10</dependency>
(Click on image to enlarge)
 sikuli14
Step #3:
Create a package inside src/test/java and Create a class inside the package. Now you can start writing the Sikuli script inside this class.

Sikuli Example Program: Open a file in Widows Explorer

Step #1:
Create a Sikuli Maven Project, as explained above.
Step #2:
Take screenshot of required elements and put it inside the Maven project.
sikuli15
– file.png
Step #3:
Create a class with name “Test1”, and Paste the following code inside the sikuli class.
1package com.test;
2 
3import org.junit.Test;
4import org.sikuli.script.FindFailed;
5import org.sikuli.script.Screen;
6 
7public class Test1 {
8 
9@Test
10public  void openFileTest() throws FindFailed, InterruptedException {
11// TODO Auto-generated method stub
12Screen s=new Screen();
13s.find("file.png");
14s.doubleClick("file.png");
15System.out.println("File icon clicked");
16 
17}
18}

Executing Sikuli Maven Project from Command line

Step #1:
Open Command Prompt and cd to the project directory.
Step #2:
Execute the above project from command prompt using the following command.
mvn clean test -Dtest=Test1
 sikuli16

Selenium Vs Sikuli

sikuli17

Integrating Sikuli With Selenium WebDriver

Step #1:
Create a new Java Project in eclipse by clicking New -> Java project.
Step #2:
  1. Right click on the Project Go to Build Path   -> Configure Build Path.
  2. Switch to Libraries Tab.
  3. Click on “Add External Jars” and Add Selenium library jars as well as Sikuli-scritp.jar
sikuli18
Step #3:
Create a package inside src/ folder and create a class under that package.
Step #4:
Take All required screenshot of web elements and save inside the project.

Step #5:
Copy the following code inside that class.
1package com.test;
2 
3import org.openqa.selenium.WebDriver;
4import org.openqa.selenium.firefox.FirefoxDriver;
5import org.openqa.selenium.support.ui.WebDriverWait;
6import org.sikuli.script.FindFailed;
7import org.sikuli.script.Screen;
8 
9public class OnlinePainting {
10 
11public static void main(String[] args) throws FindFailed {
12// TODO Auto-generated method stub
13 
14WebDriver driver=new FirefoxDriver();
15WebDriverWait wait=new WebDriverWait(driver,20);
16driver.manage().window().maximize();
17driver.get("http://www.thecolor.com/Coloring/a-puppy-with-a-kitten.aspx");
18Screen screen=new Screen();
19screen.wait("1398665726055.png", 20);
20screen.click("1398666382715.png");
21screen.click("1398666248846.png");
22screen.click("1398666729252.png");
23screen.click("1398666188894.png");
24screen.click("1398665763634.png");
25screen.click("1398666592027.png");
26screen.click("1398666610951.png");
27screen.click("1398666308624.png");
28screen.click("1398666326406.png");
29screen.click("1398666570749.png");
30screen.click("1398666703708.png");
31screen.click("1398666382715.png");
32screen.click("1398666857321.png");
33screen.waitVanish("1398665763634.png");
34 
35}
36}
Step #6:
Right click on the project, Select RunAs -> Java Application.
Before Execution:
 sikuli19
After Execution:
 sikuli20

Conclusion

  • Sikuli scripts can be easily integrated with selenium WebDriver to automate flash websites.
  • Sikuli can automate windows as well as all other applications.
  • As it uses Visual match, we can automate almost anything, we see on the screen.
  • It provides extensive support to Flash objects. i.e. we can automate adobe flash player components. (Audio player, video player)
  • Sikuli scripts can be created as maven project and can be run from command prompt.
  • Hence, Sikuli is most friendly, automation tool to automate challenging flash/windows applications.

7 comments: