Home | About | Contribute | Downloads | Documentation | FAQ |  Media 

Examples of the procedural API

gedit-test-utf8-procedural-api.py

This script launches the gedit text editor, and opens a UTF-8 encoded file containing examples of text from many languages.

The script then triggers a click on the "Save" button, and attempts to manipulate the "Save As..." dialog. However, it takes some time for this dialog to appear. Notice how dogtail looks for the dialog and automatically retries when it is not found, logging the fact that it is taking a while.

Eventually the dialog appears, and the script manipulates it, setting the location for the file, and saving the file. The script goes on to compare the written file with a master copy, to check that gedit is correctly encoding the result.

Examples of the object-oriented API

evolution-test-configuring-imap-smtp.py

This script uses Evolution; it walks through the Account configuration assistant, filling in values in all of the pages.

This script is another example of the higher-level approach; the source code to the script is very short, and most of the work is done in the Evolution wrapper class. One of the benefits of this approach is that the same script can be used with different versions of the application; this script works with both Evolution 2.0 and Evolution 2.4, despite differences in the UI. This is handled by simple logic in the wrapper.

evolution-test-configuring-exchange.py

This script is very similar to the previous one: it attempts to configure an Evolution account for talking to an Exchange server.

The movie shows the script running to failure: Evolution fails to authenticate against the server. Notice how an exception is raised, containing the text from the error dialog, and how this makes it into the log. dogtail also has facilities for capturing screenshots.

google-search.py

You can use dogtail for automating and testing web UI.

For example, you can write scripts that fill in forms on web pages, and obtain data back from the results.

This movie shows a script driving Epiphany to fill in a form on a website site.

The site in question is the front page of Google; the script carries out a search on Google and then logs the search results.

This approach can only work provided that the web browser exports the content of web pages to the accessibility layer. Not all web browsers support this, but Epiphany does.

gnome-panel-test-starting-every-app.py

You can write scripts that work with multiple applications

This movie shows a script which works with every user-visible application in the desktop panel. The script starts each one in turn, with a 5-second delay to keep things sane. I stopped it running after a while.

More complex scripts could do something to each application in turn, for example, test that on-line help starts correctly, or test that the UI is fully translated

nautilus-test-icon-view-collage.py

This final movie shows a script which use Imagemagick to chop one of my holiday photos into smaller pieces, and then rearranges the files in Nautilus' icon view to create a collage out of the thumbnails.