DogtailTutorial

Revision 1 as of 2008-01-09 18:26:52

Clear message

A quick tutorial on using dogtail, on Ubuntu gutsy.

  1. Install GNOME, if you don't have it already.
  2. Enable accessibility features: System -> Settings -> Accessibilty, then click on the "enable" tick.

  3. Log out and back in. The accessibility features won't be enabled until after you do this.
  4. Install the python-dogtail package.
  5. Run the script below with "python gedit.py".
  6. Read /usr/share/python-support/python-dogtail/dogtail/procedural.py to have a feeling for the API.

Sample program to do a simple Gedit test (save as gedit.py):

# coding=utf-8

# A small sample script for dogtail. Starts Gedit, inserts some text,
# saves it, quits Gedit, and verifies that the saved file is correct.

import os
import shutil
import tempfile

from dogtail.procedural import *

os.environ["LC_ALL"] = "C"

dirname = tempfile.mkdtemp()
filename = os.path.join(dirname, "hello.txt")
string = "hello, world"

run("gedit")

focus.application("gedit")
focus.text()
type(string)

click("Save")
focus.text()
type(filename)
focus.widget(name="Save As…", roleName="dialog")
click.button("Save")
# At this point we have what is technically called a race condition.
# The save might not have happened by the time click.button() returns,
# and so we might be quitting too early. On my desktop machine it is
# fast enough, inside qemu not.

click("Quit")

saved_string = file(filename).read()
if saved_string != string + "\n": # gedit adds a newline to the end, always!
    print "error: bad content saved"
    print repr(saved_string)
else:
    print "ok"

shutil.rmtree(dirname)