Sonntag, 5. Juni 2011

Sikuli – GUI Test Automation with Java Robot API and Images

The Sikuli project provides a simple tool for automate and test graphical user interfaces (GUI) using images (screenshots). The idea is to find an element on the screen by a screenshot and not by XPath or ID. The tool can be used for all GUIs also web applications. It’s a nice idea below you can see a simple example.


The SIKULI project is based on the Java VM and also provides an API for writing the automation in Java here a JUnit sample test.

import org.junit.Test;
import org.sikuli.script.App;
import org.sikuli.script.Screen;
public class GoogleDemoTest {
@Test
public void testGoogleSearch() throws Exception {
Screen screen = new Screen();
App app = new App("Firefox 4.app");
app.focus();
screen.click("images/homeButton.png", 0);
screen.click("images/homeUrlInput.png",0);
screen.type(null, "www.google.com", 0);
screen.click("images/goButton.png", 0);
screen.click("images/searchInput.png", 0);
screen.type(null, "tux2323", 0);
screen.click("images/searchButton.png", 0);
screen.click("images/tux2323BlogLink.png", 0);
}
}

For real world web testing it is not the right tool I think, because it depends on the style of the elements. When the button style changed you need a new screenshot of the button. But it is a nice tool for simple automation tasks. Have also a look at screen casts on the project homepage.

Links:
- Project Home - http://sikuli.org/
- How to use Sikuli Script in your JAVA programs - http://sikuli.org/docx/faq/030-java-dev.html