The most practical tutorials on Sikuli GUI automation testing tool:
In part-1 of this “introduction to Sikuli tutorial series”, we have discussed Sikuli, how it works, and how to create a simple Sikuli project.
Recommended IPTV Service Providers
- IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
- IPTVRESALE – Rating 5/5 ( 200+ Reviews )
- IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
- IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
- IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
- IPTVTOPS – Rating 5/5 ( 43 Reviews )
In this 2nd part, you are going to learn some advanced concepts like – how to create Sikuli Maven project and how Sikuli can be used with Selenium WebDriver to automate web pages.
This part is essential because there is no built-in method to open a website/web application in Sikuli. So whenever you’re executing a Sikuli script, you need to make sure that the website is already opened in a browser. It is an overhead task.
To overcome this, Sikuli can be used together with Selenium WebDriver. Selenium contains a method to open a website in a browser. After opening the website, we are able to run Sikuli scripts on that website.
What You Will Learn:
Create A Sikuli Maven Project
Installing Eclipse Maven Plugin
Step #1) Open Eclipse, Go to Help -> Install a new Software. Click on the “Add” button and add the following URL.
Click on the “OK” button.
Step #2) Check All the checkboxes listed, click “Next” and install the Maven plugin.
Installing Apache Maven
Step #1) Download the latest version of the 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 a JAVA_HOME variable in the environment variable. Please set the 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,
It indicates Maven successfully installed on 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 the maven repository.
By using the following command we can install sikuli-script.jar in the maven repository.
Mvn install: install-file -Dfile=D:JarsSikuli-r930win32Sikuli-IDEsikuli-script.jar -DgroupId=com.test.sikuli -DartifactId=sikuli -Dversion-1.0.1 -Dpackaging=jar
Creating The Sikuli Maven Project
Step #1) Open Eclipse and create a new Maven Project.
Step #2) Add the following dependencies in your POM file.
<dependency> <groupId>com.test.sikuli</groupId> <artifactId>sikuli</artifactId> <version>1.0.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> </dependency>
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 Windows Explorer
Step #1) Create a Sikuli Maven Project, as explained above.
Step #2) Take the screenshot of the required elements and put it inside the Maven project.
– file.png
Step #3) Create a class with name “Test1”, and Paste the following code inside the sikuli class.
package com.test; import org.junit.Test; import org.sikuli.script.FindFailed; import org.sikuli.script.Screen; public class Test1 { @Test public void openFileTest() throws FindFailed, InterruptedException { // TODO Auto-generated method stub Screen s=new Screen(); s.find("file.png"); s.doubleClick("file.png"); System.out.println("File icon clicked"); } }
Executing The Sikuli Maven Project From Command Line
Step #1) Open Command Prompt and cd to the project directory.
Step #2) Execute the above project from a command prompt using the following command.
mvn clean test -Dtest=Test1
Selenium Vs Sikuli
Integrating Sikuli With Selenium WebDriver
Step #1) Create a new Java Project in eclipse by clicking New -> Java project.
Step #2)
- Right-click on the Project Go to Build Path -> Configure Build Path.
- Switch to Libraries Tab.
- Click on “Add External Jars” and Add Selenium library jars as well as Sikuli-scritp.jar
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.
package com.test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.WebDriverWait; import org.sikuli.script.FindFailed; import org.sikuli.script.Screen; public class OnlinePainting { public static void main(String[] args) throws FindFailed { // TODO Auto-generated method stub WebDriver driver=new FirefoxDriver(); WebDriverWait wait=new WebDriverWait(driver,20); driver.manage().window().maximize(); driver.get("http://www.thecolor.com/Coloring/a-puppy-with-a-kitten.aspx"); Screen screen=new Screen(); screen.wait("1398665726055.png", 20); screen.click("1398666382715.png"); screen.click("1398666248846.png"); screen.click("1398666729252.png"); screen.click("1398666188894.png"); screen.click("1398665763634.png"); screen.click("1398666592027.png"); screen.click("1398666610951.png"); screen.click("1398666308624.png"); screen.click("1398666326406.png"); screen.click("1398666570749.png"); screen.click("1398666703708.png"); screen.click("1398666382715.png"); screen.click("1398666857321.png"); screen.waitVanish("1398665763634.png"); } }
Step #6) Right-click on the project, Select RunAs -> Java Application.
Before Execution:
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 a 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 a Maven Project and can be run from command prompt.
- Hence, Sikuli is most friendly, automation tool to automate challenging flash/windows applications.
Feel free to post your queries in comments.