Will put below also as part of education in uia examples thread
Understand the concept of the element hierarchy.
Especially the "technical" elements in the hierarchy confuses people.
Easiest to learn is the spying tools inspect.exe or uiaverify.exe in windows sdk, see faq 31 for links.
"Frustrating" is that not all elements in the hierarchy need to be focussed.
Rule of thumb: Set focus to mainwindow below desktop, Set focus to element to act on
Understand the search scope
Fastest way of finding elements is if you only search childs and not in grandgrandchilds.
The uia wrapper has logic to fallback to search in itself a different full hierarchy if its not found in the direct childs which is slow by nature but in my solutions highly preffered when running unattended over not finding at all
This goes fine as long as you understand bullet 1 properly otherwise you will have dozens of elements that take seconds to be found
So this line can positively influence the speed of searching as it sets the starting point to search from
_UIA_setVar("RTI.SEARCHCONTEXT", _UIA_action("title:=Calculator","getobject"))
Understand main window
In general this is just the direct window under the parent desktop (so calculator window)
Understand the concept of identifying elements by 1,n technical properties
_UIA_Action("title:=Calculator","highlight")
above will highlight the window that has calculator in the name (case independt partial search in title). 1 property is in this case enough to identify the window and act on it. The disbenefit of above its not language neutral and so a better property to use for identifying is below
_UIA_Action("class:=CalcFrame","highlight")
Its a matter of style if you put more then 1 property if only 1 is already enough to identify. The more you put in especially class can help in speeding up the search internally when i will improve search algorithm over time. So advice is to keep controltype allways in as thats a base pattern in UIA. Class is also nice as thats the core of the win32 pattern (which is mainly used in AutoIt)
Understand the difference between short coding and maintainable coding
Understand how the unwrapped core uia version would look like
todo: make later example with core UIA interface
So a basic wrapped short version can be like below
_UIA_setVar("RTI.SEARCHCONTEXT", _UIA_action("title:=Calculator","getobject"))
_UIA_Action("title:=Calculator","setfocus")
_UIA_Action("Title:=One;controltype:=Button","click")
_UIA_Action("Title:=Plus;controltype:=Button","click")
_UIA_Action("Title:=Three;controltype:=Button","click")
_UIA_Action("Title:=Equals;controltype:=Button","click")
$result=_UIA_Action("Title:=Result;controltype:=Button","gettext")
This is perfectly fine for a small demoprogram but gets more problematic when you are dealing with multiple screens or want to click 3 times the one button
You can put the one definition in a variable
$btnOne ="Title:=One;controltype:=Button"
_UIA_Action("title:=Calculator","setfocus")
_UIA_Action($btnOne,"click")
_UIA_Action("Title:=Plus;controltype:=Button","click")
_UIA_Action($btnOne,"click")
_UIA_Action("Title:=Three;controltype:=Button","click")
_UIA_Action($btnOne,"click")
_UIA_Action("Title:=Equals;controltype:=Button","click")
$result=_UIA_Action("Title:=Result;controltype:=Button","gettext")
Other options are to put it in the array and as I do I feed my definition's from a UID file which is just a name / value properties file like
calculator.mainwindow = title:=calculator
calculator.button1 = title:=One
calculator.button2 = title:=Two
Understand the slowness sometimes observed of the uiawrappers
The tough part in any wrapper is how to determine the searchscope and where to start searching and how deep
a. Starting on mainwindow and searching direct childs will result frequently in not finding the element as its on level 2 or 3
b. Starting from last element acted on in the wrapper will lead to searching for button 2 below button 1 in hierarchy which is incorrect
c. Hierarchy of browsers like chrome are sometimes terrible as it starts searching first in the html elements where you are interested in the toolbars.
So search algorithm in the wrapper is far from perfect. I have some ideas to improve but not implemented them. Ideas to find deep in tree but excluding htmldocument, listitems when search is NOT on childs.
Understand the different elements around in the world
Some elements need an invoke others need a click and some need both and some need first a setfocus before they really do what you logically want (click).
Microsoft made an excellent UIA framework but unfortunately not all parties adapted it when building windows software.
Understand automation frameworks
This is a nice summary but selenium is definitely no the only reference (selenium has many limitations as it only has focus on browsers/webdriver) http://www.softwaretestinghelp.com/test-automation-frameworks-selenium-tutorial-20/So maybe it looks complex compared to directly have coding like below (coded ui testing) the benefit of a framework is abstraction in multiple layers so you can generalize the generic parts like synchronizing, taking snapshots, logging etc after each step executed.
controlclick("class:=calc")