Friday, February 19, 2010

How to access a test object's AutomationPatterns

If your business is automating WPF applications you should know all about UI Automation Control Patterns. If you do and you wish you could access some automation pattern properties on your TO's, there's a very convenient way: you can access an automation pattern either by name or by index. for example:
WpfWindow("window").WpfListView("list").AutomationPattern("Selection").GetSelection()
will return an AutomationElement that is the current selection in the list.
I found this extremely useful when tackling text containers. The following call returns text from a TextBox, Label or any other TextPattern implementor:
WpfWindow("window").WpfEdit("textBox1").AutomationPattern("Text").DocumentRange.GetText(-1)

Next up: using a similiar technique to retrieve values from a wpf grid !

Tuesday, February 16, 2010

UISpy - the tool you must know

You dont have to use QTP's built in object spy on WPF controls

Now how good does that sound like ?
If you ever given QTP a chance with your WPF AUT, i bet it does.
Anyway, there's this wonderful tool that is based on MS's UIAutomation framework (this is the framework QTP's WPF support is built upon). What it does is actually quite similiar to the good ol' object spy, just that it actually works on WPF controls and showing you the entire application hierarchy (QTP 9.2's object spy stops at the moment it recognizes one control that isn't a window, though i think there might be a hotfix for that).

You can find further documentation on this msdn page (notice comments about it being mistakenly removed from the Windows SDK 6.0A, but it's back if you have windows 7 and you can download it separately anyway)

Enjoy