UI Test Automation with Sikuli and Selenium WebDriver in Java

By: Slav Kurochkin

This post is the introduction to UI Test Automation with Sikuli and Selenium WebDriver. You can learn how to setup basic project in Java using Maven dependencies. Then we going to create UI test.

1. Create Maven Project
2. Add maven dependencies
3. Add chromedriver.exe or use FirefoxDriver
4. Create java class with main method
5. Create images folder and place screenshots of the UI elements
6. Run the tests

Test Automation with Sikuli and Selenium WebDriver

1. Create Maven project.

Open your ide (in example IntelliJ IDEA). Then click on File > New > Project.... Then select Maven project and hit Next button.

Sikuli and Selenium UI Testing create maven project
Sikuli and Selenium UI Testing select maven project

Type maven groupId and atifactId

Sikuli and Selenium UI Testing create maven projectSikuli and Selenium UI Testing create maven groupId and atifactId

Give this project a name:

Sikuli and Selenium UI Testing create maven projectSikuli and Selenium UI Testing create maven project name

2. Add maven dependencies

Now we need add Maven dependecies, open pom.xml and add following snippet:

3. Add chromedriver.exe or use FirefoxDriver

It is totally up to you what browser to run against. I want my test run against Chrome. Download chromedriver.exe and place it in src/main/resources.

4. Create java class with main method

Now lets add java class with main method containing. Open src > main > java. Right click on java folder and add new class (SikuliAndSeleniumTest.java in example).
here the snippet I have for my simple test:

5. Create images folder and place screenshots of the UI elements

As you can see in code snippet I have to provide images for Sikuli, since Sikuli working based on image recognition principal. Lets add images folder in same path where our src is located. Once the folder is created if you followed the steps from tutorial your project structure would look similar to mine:

Sikuli and Selenium project structureSikuli and Selenium project structure

You have to provide images to Sikuli, on windows you can use default Snipping tool to take specific areas screenshots:

Sikuli and Selenium UI Testing create maven project
Sikuli and Selenium UI Testing create maven project

So what you should take screenshot of? Well you should screenshot exact element you wish to interact with. Lets say you want interact with Google Chrome URL bar. Then just take a screenshot of this area, give it unique name and place it to images folder we created riecnetly. Now you can add Sikuli comand to interact with this element, your snippet would be something like this:

Screen screen = new Screen();

screen.click("images/search.PNG");
screen.type("Sikuli and Selenium UI Testing" + Key.ENTER);

6. Run the tests

Once everything in place you can run your test. Since there is no test runner, you can right click on either the main method or the class and hit green play button.

View Comments

Leave a Comment

Use markdown or basic HTML and be nice.