Image-Based Test Automation Using Sikuli
This article explains how to interact with web elements using images integrating Selenium and Sikuli APIs.
Join the DZone community and get the full member experience.Join For Free
Sikuli is an open source test automation tool for testing web applications. It is similar to Selenium, but it considers all the web elements of the application as images. This tool is capable of recognizing images and interacting with the elements matching the image GUI.
How to Use Sikuli in an Eclipse-Maven Project
Step 1: Create a Maven project called "SikuliProject".
Step 2: Add the Sikuli jar to the pom.xml file in order to load the Sikuli library to our project.
Step 3: Add a Selenium dependency to support loading the browser, opening the application URL, etc.
Step 4: Create a script using two main classes – "Screen" and "Pattern" – and perform testing of web applications.
This is the main class of the Sikuli API. It contains various built-in methods to perform actions on web elements.
Below are some commonly used
Screen() class methods:
click()-> Clicks on an element referred to by the image name.
doubleclick()-> Double clicks on an element referred to by the image name.
delayClick()-> Clicks an element after the given time in milliseconds.
delayType()-> Introduces a delay in milliseconds between each character at next type.
type()-> Type the given text as an argument.
It is used to uniquely identify the web element based on the image stored in a specific location.
Syntax: Pattern p = new Pattern("Location of image saved");
Example Demo for Login:
Step 1: Identify the web elements to perform login, capture images, and store them in your hard drive.
Step 2: Images captured for our demo are given below:
- Login link
- Username textbox
- Password textbox
- Login Button
- Logout Link
Sikuli is used widely when Selenium has difficulty recognizing the elements or when there is a need to perform image-based element recognitions. Thanks for reading this article on how to integrate Selenium-Sikuli and perform image-based testing.
Opinions expressed by DZone contributors are their own.