SetTrap checks for the existence of the specified windows at each 4Test statement that involves a call to the Agent. Statements not included are function calls, SYS_* calls, and any flow control statements (if, while, do/except, and so on).
This method is equivalent to Exists, except that it is perpetual; that is, the trap triggers in those instances when Exists would return TRUE.
When a trap condition is detected (that is, the window appears), Silk Test Classic presses the pushbutton specified by ButtonTag. If you specify iExceptNum, SetTrap also raises the specified exception. To raise an exception without pressing a button, specify an empty tag ("") for ButtonTag.
This function is useful for responding automatically to message boxes such as "Save changes?" or to dialogs from a network. You can set traps for any number of windows.
SetTrap is very timing dependent. It has to catch the window as it is opening. If SetTrap is triggered out of step with the appearance of its assigned window, then SetTrap does not trap it. Once SetTrap misses the opening of the window, it will not trap it at the next statement that triggers it because the window is already established.
SetTrap allocates memory, and so should be followed by a call to ClearTrap as soon as the window is found. Clearing traps is essential for maintaining performance at a useable level. We recommend that you set a trap only once per script, or alternatively, that you define your own ScriptEnter function that sets the trap on a script-level basis.
Use the tag /~/$SystemModal to trap system modal dialogs (if they have a caption). For example:
DialogBox("/~/$SystemModal").SetTrap ("Cancel")
The following example shows when SetTrap performs its check for the existence of a window.
[ ] MessageBox.SetTrap ("Yes") [ ] MyWin.SetActive() // SetTrap checks [-] if (NOSHOESHINE) // no check [ ] MyWin.MyButton.Click() //SetTrap checks [-] while (BOGUS) // no check [ ] exit // no check [ ] Agent.GetOption() // SetTrap checks