UI Automation | Set Root For AUT

The code below demonstrate the usage of SetRoot method for UI automation.  When a root is set, the Testmate engine accepts the newly set object as parent instead of the desktop.

By doing this, the performance of the scripts can be improved as it reduces the time of object identification.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'Declare the root object
'Declare the root object
oWindow = "Window,Name::Calculator"
 
'By using this , the hierarchy can be skipped as below
oTwo = "Button,Name::Two"
oThree = "Button,Name::Three"
oFour = "Button,Name::Four"
 
'Open Calculator App
Set oShell = CreateObject("Wscript.shell")
oShell.Run "Calc"
 
'Wait for the button to show up
bSync = uia.Exist(oWindow)
util.Wait(1)
 
'Set the parent window as root - This will improve the script performance
'All the objects will be located considering this window as root instead of the default desktop
uia.SetRoot oWindow
 
'Click on 2,3,4 buttons
uia.Click oTwo
uia.Click oThree
uia.Click oFour
 
'Set the desktop as the default Parent
uia.ResetRoot

Add a Comment

Your email address will not be published. Required fields are marked *