[TIP] Python GUI testing
Gary Bernhardt
gary.bernhardt at gmail.com
Mon Apr 4 14:43:15 PDT 2011
On Mon, Apr 4, 2011 at 12:33 PM, Geoff Bache <geoff.bache at gmail.com> wrote:
> Right, but does that include internally set names? Things like Text
> boxes, Trees and Tables
> don't have a title or label, and in those cases it's pretty useful to be able
> to explicitly name them and use that name in the tests. Also, sometimes several
> widgets have the same label.
Ahh, you're right. My tests would just directly address the text
fields etc. by their order in the view. I feared this at first, but it
didn't end up being a major problem for a few reasons:
- AppleScript supplies the controls in an order that seems to always
make sense. I think it was top-left to bottom-right, rather than some
arbitrary database-natural order.
- You shouldn't be creating views with tons of text boxes! ;)
- My tests never directly named fields. They always called into a
layer of abstraction on top of appscript. Instead of saying "fill in
text field 1 with the path", they'd say
"set_protected_folder_path(path)". Any control change would result in
only one change to the tests because no control was named twice.
Because of AppleScript/System Events' nice ordering, you could go one
step further and write something like:
def fill_in_text_box(label_name, text):
skip controls until you see a label with label_name
skip controls until you see any text field
put the text in whatever we have; it's the text field to the right
of the target label
It's the same basic principle as "find the HTML label with text
'username' and put the username in its corresponding input" you'd do
in web UI testing, except it relies on stable control ordering instead
of explicit linkage between the label and text field.
> Interesting. A quick look at AppleScript made it look like the Mac is
> somewhat further on in this respect than other platforms from what I
> could tell.
Yep, it's awesome. I was very surprised. It's existed for a long time, too.
--
Gary
http://blog.extracheese.org
More information about the testing-in-python
mailing list