Add method for dumping widget and its children to stdout

Bug #1241323 reported by Martin Pitt on 2013-10-18
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Martin Pitt
autopilot (Ubuntu)
rosa maria

Bug Description

When writing autopilot tests, finding the type and exact properties of the exact widget that I'm seeing somewhere on the screen is one of the biggest challenges. Many widgets can get an explicit identifier (objectName in QML or GtkBuilder ID in Gtk), but often this doesn't help: For example the actually visible labels in a QML list view are hidden many layers benath some unintelligible nested QtQuickItem, HandlerDelegate, and other bits, which makes finding anything in vis hard.

So I often temporarily add a snippet like

    widgets = set()
    self._get_widgets(, widgets)
    for c in widgets:
        for p in c.get_properties():
            print ' ', p, repr(getattr(c, p))

    def _get_widgets(klass, obj, widget_set):
        """Recursively add all children of obj to widget_set"""

        for c in obj.get_children():
            klass._get_widgets(c, widget_set)

to just dump a particular parent widget (like said list view) and recursively all of its children to stdout, where it's easy to find with grep or just by looking if there aren't too many children.

I'd like to add this to AP itself, with some prettyness: Proper indentation according to nesting level, output to a file name, and so on.

Related branches

Martin Pitt (pitti) on 2013-10-18
Changed in autopilot:
importance: Undecided → Wishlist
assignee: nobody → Martin Pitt (pitti)
Thomi Richards (thomir) wrote :

Should probably also limit the number of levels deep you go, but it sounds nice. Maybe allow the author to pass in a file-like object to write to, but default to sys.stdout?

Changed in autopilot:
status: New → Triaged
Martin Pitt (pitti) wrote :

Yes, I was planning to do that. Something like

  def write_property_tree(self, output=None, maxdepth=None):

where output defaults to sys.stdout (for None), but can be either a file name or a file object. For large trees it's convenient to do something like recursive_properties('/tmp/dump.txt'), for small trees stdout is fine. With maxdepth you can optionally limit the depth.

I'd appreciate some better ideas about the name; in my test case I just call it "dump()" usually, but this name is rather overloaded and ambiguous.

Martin Pitt (pitti) wrote :

MP created.

Changed in autopilot:
status: Triaged → In Progress
PS Jenkins bot (ps-jenkins) wrote :

Fix committed into lp:autopilot at revision 361, scheduled for release in autopilot, milestone 1.4

Changed in autopilot:
status: In Progress → Fix Committed
Thomi Richards (thomir) on 2013-11-07
Changed in autopilot:
milestone: none → 1.4
status: Fix Committed → Fix Released
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package autopilot - 1.4+14.04.20131125-0ubuntu1

autopilot (1.4+14.04.20131125-0ubuntu1) trusty; urgency=low

  [ Leo Arias ]
  * On the log_action decorator, do not duplicate the ending period.
    (LP: #1248751)

  [ Robert Bruce Park ]
  * Rename autopilot-py3 to more conventional autopilot3.
  * Drop dependency on python-ubuntu-platform-api, since it does not
    support python3.

  [ Christopher Lee ]
  * Update the osk keyboard backend. . (LP: #1243477)

  [ Thomi Richards ]
  * Add more documentation around object ordering. (LP: #1248336)
  * Add method to wait for a proxy object to be destroyed. (LP:
  * Fix a bug in the autopilot type system, and add missing unit tests
    for that issue. (LP: #1249096)
  * Add a mockable sleep, so we can run autopilot unit tests quickly.

  [ Martin Pitt ]
  * Add print_tree() introspection method for writing a textual
    representation of the object and all of its children to stdout, a
    file object, or a file name. (LP: #1241323)

  [ Corey Goldberg ]
  * added failfast (-ff|--failfast) command line option to autopilot
    run. (LP: #1248634)

  [ Ubuntu daily release ]
  * Automatic snapshot from revision 368
 -- Ubuntu daily release <email address hidden> Mon, 25 Nov 2013 06:30:17 +0000

Changed in autopilot (Ubuntu):
status: New → Fix Released
Changed in autopilot (Ubuntu):
assignee: nobody → rosa maria (rprosamaria383)
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers