I spent a few days learning to use Autopilot. This is a tool originally designed to test Unity, which has been extended to test Qt and GTK applications. In this article I will explain how it works especially in the case of GTK applications.
Autopilot is twofold: on the one hand, it is a set of modules built into each toolkit (GTK, Qt, etc…) to get information about the widgets displayed (such as the position, the content…). On the other hand, it is a Python library which can be used to write efficient tests. Yes, you will need to know Python to write tests, but it is a wonderful, fast, and easy to learn language. The choice of Python is especially good to write tests: they do not need to be super fast, and it is more practical to not re-compile them every time you do a change in your test code.
How to install Autopilot
I will only cover Ubuntu here, but the method to install it must be similar on other platforms.
If you are lucky, there are already the packages in the repositories (for Raring and Saucy), so just install autopilot-desktop and python-autopilot:
sudo apt-get install autopilot-desktop python-autopilot
If you are using Precise (or Quantal, but it has not been tested on it), just install these packages on your computer, copied from the Raring ppa there: https://launchpad.net/~autopilot/+archive/ppa (just adjust the names if you are using an amd64 or an i386 computer): autopilot-desktop, python-autopilot-trace, python-autopilot-vis, python-autopilot, libautopilot-gtk, libxpathselect. Download all these files in a folder, then do:
sudo dpkg -i *.deb
(Yes, this is not the cleanest way to install packages, but it works and backporting everything properly would just be a waste of time.)
Running the tests
I wrote two small tests suites for the elementary project. The first one is for Scratch, but I will not show it here (it is on Launchpad tough), because it needs a patch in autopilot-gtk that I am trying to get upstream.The other one is the Pantheon Terminal test. Currently, it only tests the tabs, but it aims to test more part in the future. The code is in lp:~xapantu/pantheon-terminal/tests.
cd elementary # if you have a clean elementary folder with all your development stuff mkdir tests cd tests bzr branch lp:~xapantu/pantheon-terminal/tests pantheon-terminal # it is important to name the branch pantheon-terminal autopilot run pantheon-terminal # if you do not use JHBuild jhbuild run autopilot pantheon-terminal # for people who use JHBuild
You can then read the code to learn how extend them.
Why not LDTP or dogtail?
LDTP and dogtail are the two other softwares used to write GUI test that I am aware of. Both use the accesibility API only (via D-BUS), without any modules linked to the toolkit. While it is theorically more flexile, in my experience, it can lead to some nasty refresh bugs (especially in a GtkNotebook), that I did not encounter with Autopilot (it does not mean it is bug free though).
Moreover, after having tested these three solutions, I eventually prefered the Autopilot API (which is entirely subjective).
I will write an article to explain how to write the tests in detail (and how to use autopilot vis, etc…) in the following days.