Previous topic

How to run Sikuli from Command Line

Next topic

How to use Sikuli Script in your JAVA programs

This Page

How to create Unit Testing Scripts for GUI

Sikuli integrates with jUnit and supports unit testing for Graphical User Interfaces (GUI). The unit testing panel can be opened by clicking the menu View ‣ Unit Test or by the hot key ⌘-U on Mac or Ctrl-U on Windows/Linux.

Sikuli IDE aims to minimize the effort of writing code. With Sikuli IDE, a Python class inherited from junit.framework.TestCase is automatically generated to wrap your unit testing script.

A typical unit testing script consists of two constructing and destructing methods, setUp() and tearDown(), and a bunch of methods named with a prefix test.

The basic structure of a script is given as following:

1def setUp(self):
2  openApp("AnyRandom.app")
3  wait(SCREENSHOT_OF_THE_APP) # wait until the app appears
4
5def tearDown(self):
6  closeApp("AnyRandom.app")
7  untilNotExist(SCREENSHOT_OF_THE_APP) # wait until the app disappears
8
9def testA(self):
10  ....
11  assert exists(PICTURE_THAT_SHOULD_BE_THERE)
12
13def testB(self):
14  ....
15  assert not exists(PICTURE_THAT_SHOULD_NOT_BE_THERE)

Here is a complete example.

To run a unit testing script, you need to click on the Run button in the unit testing panel instead of the ordinary button.

IMPORTANT: Before you try to run your script in this test mode the first time, it has to be saved. Everytime you change something, you have to save it again, before the next test run.

Alternatively, you also can run unit testing scripts from command line using the option -t test-script.