Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

When using SetTrap, SilkTest Help recommends that it is only used once in a script, how can this be overcome if I have to use it in multiple testcases?

When using SetTrap, SilkTest Help recommends that it is only used once in a script, how can this be overcome if I have to use it in multiple testcases?

When using SetTrap in SilkTest, you can use it more than once in a script by defining your own TestCaseEnter function that sets the trap on a testcase-level basis. SetTrap will be called each time a testcase is entered which can be multiple times within a script depending on the amount of testcases you are running.

Please make sure that you call the ClearTrap() function at the end of the testcase or in a separate TestCaseExit function that gets called when SilkTest exits a testcase.

Please see below an example of how this can be done:

This example is using Google

Frame file example

[ ] const wMainWindow = Google
[ ] 
[-] window BrowserChild Google
    [ ]  tag "Google"
    [ ] 
    [ ]  // The URL of this page
    [ ]  const sLocation = "http://www.google.com/webhp?sourceid=navclient&ie=UTF-8"
    [ ] 
    [ ]  // The login user name
    [ ]  // const sUserName = ?
    [ ] 
    [ ]  // The login password
    [ ]  // const sPassword = ?
    [ ] 
    [ ]  // The size of the browser window
    [ ]  // const POINT BrowserSize = {600, 400}
    [ ] 
    [ ]  // Sets the browser font settings to the default
    [ ]  // const bDefaultFont = TRUE
    [ ] 
[ ] 
[ ] 
[-] TestCaseEnter ()
    [ ] print ("TestCaseExit function has been executed") 
 [ ] // putting your SetTrap() function here means it would be 
    [ ] // called each time a testcase is entered which may
    [ ] // be multiple times in a script
[ ] 
[-] TestCaseExit (BOOLEAN bException)
    [+] if (bException)
        [ ] ExceptLog ()
    [ ] print ("TestCaseExit function has been executed")
 [ ] // you could put your ClearTrap() function here and it would be 
    [ ] // called each time a testcase is exited.

Script file example

[-] main ()
    [ ] integer i
    [-] for i = 1 to 10
        [ ] one ()
        [ ] 
[ ] 
[-] testcase one () appstate none
    [ ] print ("The testcase has executed")

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:16
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.