Need API to select widget by property list
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Autopilot |
Invalid
|
Undecided
|
Unassigned |
Bug Description
There seem to be two methods for accessing the widget tree: get_children(), which gets you all children, and get_children_
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_
class UnityIntrospect
DBUS_SERVICE = "com.canonical.
DBUS_OBJECT = "/com/canonical
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)
Hi,
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: https:/ /code.launchpad .net/~thomir/ autopilot/ fix-docs/ +merge/ 137453
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
*kwargs*.
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.
Cheers,