WindowChildren Function

Action

Returns the children of a window, as specified in the declaration.

Syntax

lwChildren = WindowChildren (wWindow [, GUIType])
Variable Description
lwChildren The children of the window. LIST OF WINDOW.
wWindow The window whose children you want. WINDOW.
GUIType Optional: The GUI for which to return child windows. The default is the current GUI. GUITYPE.

Notes

WindowChildren returns the child windows (from the window declaration) of the specified window on the current GUI or on GUIType, if GUIType is specified. The function also returns the window parts of the specified window, as defined in the class. For a list of window parts, see the MoveableWin class.

Open Agent Example

To quickly detect any unwanted structural changes in your application under test (AUT), you can use Silk Test Classic to verify that your AUT correctly displays all included controls. This example describes how you can use the WindowChildren with the GetChildren function of the AnyWin class to compare the actual windows in your AUT with the expected windows. The following code defines a set of windows that are expected to be child windows of Notepad.
		[-] TextField TextField
			[ ] locator "//TextField"
		[-] MenuItem AboutNotepad
			[ ] locator "About Notepad"
		[-]  DialogBox AboutNotepadDialog // This window is only found if the About dialog box is open.
			[ ] locator "About Notepad"
			[-] PushButton OK
				[ ] locator "OK"
The sample script uses the WindowChildren function to retrieve the defined child windows of Notepad, and the GetChildren function to retrieve the actual windows of Notepad. Then the script compares the defined windows with the actual windows and returns the following three lists:
  • Windows that are expected and actually included in Notepad.
  • Windows that were unexpectedly added to Notepad.
  • Windows that are expected but missing from Notepad.
For your application under test, only the first list should include windows.

The entire script looks like the following:

[ ] const wDynamicMainWindow = UntitledNotepad
[ ] 
[-] window MainWin UntitledNotepad
	[ ] locator "/MainWin[@caption='Untitled - Notepad']"
	[ ] 
	[ ] // The working directory of the application when it is invoked
	[ ] const sDir = "C:\"
	[ ] 
	[ ] // The command line used to invoke the application
	[ ] const sCmdLine = "C:\Windows\system32\notepad.exe"
	[ ] 
	[ ] // The list of windows the recovery system is to leave open
	[ ] // const lwLeaveOpenWindows = {?}
	[ ] // const lsLeaveOpenLocators = {?}
	[-] TextField TextField
		[ ] locator "//TextField"
	[-] MenuItem AboutNotepad
		[ ] locator "About Notepad"
	[-]  DialogBox AboutNotepadDialog // this won't be found
		[ ] locator "About Notepad"
		[-] PushButton OK
			[ ] locator "OK"
[ ] 
[ ] 
[-] type WindowVerificationResult is record
	[ ] LIST OF WINDOW verifiedWindows
	[ ] LIST OF STRING newWindows
	[ ] LIST OF WINDOW missingWindows
[ ] 
[ ] 
[-] WindowVerificationResult VerifyWindowChildren(WINDOW windowToVerify)
	[ ] WindowVerificationResult result
	[ ] LIST OF WINDOW childrenDecls = WindowChildren(windowToVerify)
	[ ] LIST OF WINDOW resolved
	[ ] WINDOW w
	[ ] LIST OF WINDOW missingControls
	[-] for each w in childrenDecls
		[-] do
			[ ] ListAppend(resolved, w.resolve({0, true}))
			[ ] ListAppend(result.verifiedWindows, w)
		[-] except
			[ ] ListAppend(result.missingWindows, w)
	[ ] 
	[ ] LIST OF WINDOW actualChildren = windowToVerify.GetChildren()
	[-] for each w in actualChildren
		[ ] INTEGER foundIndex = ListFind(resolved, w)
		[-] if(foundIndex == 0)
			[ ] LIST OF STRING locatorParts = w.GenerateLocator()
			[ ] STRING part
			[ ] STRING combinedLocator = ""
			[-] for each part in locatorParts
				[ ] combinedLocator += part
			[ ] ListAppend(result.newWindows, combinedLocator)
	[ ] 
	[ ] return result
	[ ] 
[ ] 
[-] testcase VerifyNotepad()
	[ ] WindowVerificationResult result = VerifyWindowChildren(UntitledNotepad)
	[ ] Print("Verified Windows: {result.verifiedWindows}")
	[ ] Print("New Windows:      {result.newWindows}")
	[ ] Print("Missing Windows:  {result.missingWindows}")
When replayed, this script returns the following:
[ ] Script windowChildren.t - Passed
[ ] Machine: (local)
[ ] Started: 09:48:37AM on 15-Jul-2015
[ ] Elapsed: 0:00:08
[ ] Passed:  1 test (100%)
[ ] Failed:  0 tests (0%)
[ ] Totals:  1 test, 0 errors, 0 warnings
[ ] 
[-] Testcase VerifyNotepad - Passed
	[ ] Verified Windows: {UntitledNotepad.TextField, UntitledNotepad.AboutNotepad}
	[ ] New Windows:      {/MainWin[@caption='Untitled - Notepad']//Menu[@caption='File'],
	[ ]  /MainWin[@caption='Untitled - Notepad']//Menu[@caption='Edit'],
	[ ]  /MainWin[@caption='Untitled - Notepad']//Menu[@caption='Format'],
	[ ]  /MainWin[@caption='Untitled - Notepad']//Menu[@caption='View'],
	[ ]  /MainWin[@caption='Untitled - Notepad']//Menu[@caption='Help']}
	[ ] Missing Windows:  {UntitledNotepad.AboutNotepadDialog}
This result shows that five windows are included in Notepad, which are not included in the expected set. For future testing, we should include these windows in the expected set. The result also shows that one window, which is included in the expected set, is not included in Notepad. This could have two reasons.
  1. Notepad should include this window, but wrongly does not. In this case, we have found an error in the AUT, and we need to take the appropriate actions.
  2. The window has been deliberately removed from the AUT by an application developer. In this case, we need remove the window from the expected window set.

Classic Agent Example

[-] window DialogBox Find
	[ ] tag "Find" 
	[ ] parent TextEditor
	[-] StaticText FindWhatText
		[ ] tag "Find What:" 
	[-] TextField FindWhat
		[ ] tag "Find What:"
	[-] CheckBox CaseSensitive
		[ ] tag "Case sensitive" 
	[-] StaticText DirectionText
		[ ] tag "Direction" 
	[-] PushButton FindNext
		[ ] tag "Find Next" 
	[-] PushButton Cancel
		[ ] tag "Cancel" 
	[-] RadioList Direction 
		[ ] tag "Direction"
[-] main ()
	[ ] ListPrint (WindowChildren (Find)) 
[ ] // this script prints:
[ ] // Find.FindWhatText
[ ] // Find.FindWhat
[ ] // Find.CaseSensitive
[ ] // Find.DirectionText
[ ] // Find.FindNext
[ ] // Find.Cancel
[ ] // Find.Direction
[ ] // Find.BottomEdge
[ ] // Find.LeftEdge
[ ] // Find.RightEdge
[ ] // Find.TopEdge
[ ] // Find.BottomLeftCorner
[ ] // Find.BottomRightCorner
[ ] // Find.TopLeftCorner
[ ] // Find.TopRightCornerNotes