Need API to select widget by property list

Bug #1082388 reported by Martin Pitt
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

There seem to be two methods for accessing the widget tree: get_children(), which gets you all children, and get_children_with_type(type, prop1=value1, ...).

get_children() is inconvenient as you have to do all the property matching yourself, and as this is the very core job of a testing framework like autopkgtest it should provide this searching/filtering mechanism.

get_children_with_type() doesn't seem useful, as I do not have Python classes which I can use as a type. Unity's test use this shim:

class UnityIntrospectionObject(DBusIntrospectionObject):

    DBUS_SERVICE = "com.canonical.Unity"
    DBUS_OBJECT = "/com/canonical/Unity/Debug"

but that only works with processes which expose themselves on D-BUS. E. g. evince only has a private address on the session bus, not a well-known name, so I cannot use this approach either. And even then, it's a lot of overhead to set up stub classes for every widget type I want to filter on, if all that I want is "give me the window called EvWindow" on the root tree.

(Context: trying to write some tests for evince or gedit for evalutating autopilot with GTK, see bug 1082385)

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :


A couple of things:

First, get_children and get_children_by_type only return the immediate children of the object you call that method on. It allows you to specify a string as the first argument, in case you don't have an emulator class defined. This was missing from the get_children_by_type method, but there's a MP that fixes that here:

So you should be able to do:

obj.get_children_with_type('MyType', prop1=value1, ...)

Second, the application proxy object has methods 'select_single' and 'select_many' which take *exactly* the same arguments, but will select an object from the entire application tree. The docstring for select_single is at least accurate:

        """Get a single node from the introspection tree, with type equal to
        *type_name* and (optionally) matching the keyword filters present in

        For example:

        >>> app.select_single('QPushButton', objectName='clickme')
        ... returns a QPushButton whose 'objectName' property is 'clickme'.

        If nothing is returned from the query, this method returns None.

        :raises: **ValueError** if the query returns more than one item. *If you
         want more than one item, use select_many instead*.


I hope this resolves this issue for you. I'm marking the bug as invalid - please feel to re-open it if you still have issues.


Changed in autopilot:
assignee: nobody → Thomi Richards (thomir)
status: New → Invalid
Revision history for this message
Martin Pitt (pitti) wrote :

Thanks Thomi!

get_children_by_type() crashes, I reported this as bug 1091568. But select_single()/select_many() seem to work, which is by and large what I need anyway. So indeed this solves this bug.

Now I'm stuck with the fact that the really interesting properties don't seem to appear in "vis", but I'll examine this more closely.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers