Академический Документы
Профессиональный Документы
Культура Документы
(https://www.guru99.com/)
Introduction to Sikuli
Sikuli Integration with selenium webdriver
Pattern class in Sikuli
Code Example for File Upload using Sikuli
The below sequence is the list of steps to configure Sikuli with selenium webdriver.
Step 1) Download the Sikuli JAR file from the below URL.
https://mvnrepository.com/artifact/com.sikulix/sikulixapi/1.1.0
(https://mvnrepository.com/artifact/com.sikulix/sikulixapi/1.1.0)
Step 2) Create a new JAVA project in Eclipse and add the JAR file to build path, along with
selenium jar files using Right Click on the project -> Build Path -> Configure Build Path
https://www.guru99.com/sikuli-tutorial.html 1/10
12/13/2018 File Upload using Sikuli in Selenium Webdriver
(/images/1/011618_1213_SikuliTutor2.png)
Once you have added the JAR file to project build path, classes provided by Sikuli can be
used.
s.click("QA.png");
The following are the most commonly used methods of Pattern class.
String filename =
p.getFileName();
https://www.guru99.com/sikuli-tutorial.html 3/10
12/13/2018 File Upload using Sikuli in Selenium Webdriver
package com.sikuli.demo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;
import org.openqa.selenium.chrome.ChromeDriver;
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
String filepath = "D:\\Guru99Demo\\Files\\";
String inputFilePath = "D:\\Guru99Demo\\Files\\";
Screen s = new Screen();
Pattern fileInputTextBox = new Pattern(filepath + "FileTextBox.PNG");
Pattern openButton = new Pattern(filepath + "OpenButton.PNG");
WebDriver driver;
Code Explanation:
Step 1) The first statement involves setting the driver executable path for chrome.
Step 2) Use a screengrab tool such as Snipping Tool to take screenshots of windows popup
'FileTextBox' and 'Open' button.
https://www.guru99.com/sikuli-tutorial.html 4/10
12/13/2018 File Upload using Sikuli in Selenium Webdriver
(/images/1/011618_1213_SikuliTutor3.png)
(/images/1/011618_1213_SikuliTutor5.png)
Images for windows file input text box and open button are stored onto 'FileTextBox.PNG'
and 'OpenButton.PNG'.
Sikuli uses the technique of Image Recognition to recognize elements on the screen. It finds
elements on screen solely based on their images.
Example: If you want to automate the operation of opening notepad, then you need to store
the image of a desktop icon for notepad onto a PNG file and perform click operation on it.
In our case, it recognizes the file input text box and opens button on Windows popup using
the images stored. If the screen resolution changes from image capture to test script
execution, the behavior of Sikuli would be inconsistent. Hence it is always advisable
to run the test script on the same resolution at which images are captured. Change in
pixel size of images will result in Sikuli throwing a FindFailed exception.
Step 3) The next statements include the creation of objects for Screen and Pattern classes.
Create a new screen object. Set the path of the file you want to upload as a parameter to the
Pattern object.
https://www.guru99.com/sikuli-tutorial.html 5/10
Step
12/13/20184) The below statements involveFile
opening chrome
Upload using browser
Sikuli in Selenium with the URL:
Webdriver
http://demo.guru99.com/test/image_upload/index.php
(http://demo.guru99.com/test/image_upload/index.php)
driver.findElement(By.xpath(".//*[@id='photoimg']")).click();
Step 6) Wait for the windows popup to appear. Wait method is used to handle the delay
associated with opening windows pop up after clicking on the browse button.
s.wait(fileInputTextBox, 20);
Step 7) Type the file path onto input file text box and click on Open button
driver.close();
Output:
https://www.guru99.com/sikuli-tutorial.html
(/images/1/011618_1213_SikuliTutor6.png) 6/10
Clicks
12/13/2018on the 'Choose File' button, windows file
File Upload popup
using Sikuli in screen will appear. Enters data into
Selenium Webdriver
(/images/1/011618_1213_SikuliTutor7.png)
Below screen is displayed once the file upload is complete and closes the browser
(/images/1/011618_1213_SikuliTutor8.png)
Conclusion:
Sikuli is used to handle flash objects on a web page and windows popups with ease. Sikuli is
best used when the elements on user interface do not change frequently. Owing to this
disadvantage, from an automation testing perspective, Sikuli is given less preference
compared to other frameworks such as Robot and AutoIT.
Next (/gecko-marionette-driver-selenium.html)
Selenium Tutorials
42) SSL Certificate Error Handling (/ssl-certificate-error-handling-selenium.html)
(https://www.facebook.com/guru99com/)
(https://twitter.com/guru99com)
(https://www.youtube.com/channel/UC19i1XD6k88KqHlET8atqFQ)
(https://forms.aweber.com/form/46/724807646.htm)
About
About US (/about-us.html)
Advertise with Us (/advertise-us.html)
Write For Us (/become-an-instructor.html)
Contact US (/contact-us.html)
Career Sugges on
SAP Career Suggestion Tool (/best-sap-module.html)
Software Testing as a Career (/software-testing-career-
complete-guide.html)
Certificates (/certificate-it-professional.html)
Interes ng
Books to Read! (/books.html)
Suggest a Tutorial
Blog (/blog/)
https://www.guru99.com/sikuli-tutorial.html 9/10
12/13/2018 Quiz (/tests.html) File Upload using Sikuli in Selenium Webdriver
Review (/best-ergonomic-mouse.html)
Execute online
Execute Java Online (/try-java-editor.html)
Execute Javascript (/execute-javascript-online.html)
Execute HTML (/execute-html-online.html)
Execute Python (/execute-python-online.html)
https://www.guru99.com/sikuli-tutorial.html 10/10