March 12, 2018
UI Automation | Set Root For AUT
The code below demonstrates 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 29 30 31 32 33 34 35 36 37 38 39 40 41 | '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" oResult = "Text,AutomationId::CalculatorResults" '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 desktop uia.SetRoot oWindow 'Set algorithm to search anywhere under root uia.SearchElementBySubtree() 'Click on 2,3,4 buttons uia.Click oTwo uia.Click oThree uia.Click oFour 'Fetch the result sText = uia.GetProperty(oResult,"Name") 'Make validation If sText="Display is 234" Then Logger.Pass "Step1", "Calculator displays correct result", True Else Logger.Fail "Step1", "Calculator displays incorrect result as" & sText, True End If 'Set the desktop as the default Parent uia.ResetRoot |