| || |
The Sleep function is extremely useful when testing Web applications with SilkTest. Some methods, Exists () for example, don't always wait for the page to fully load. Therefore, you may get back FALSE from the method when an object actually exists. By adding a Sleep (n), where n is usually between 2-5, many problems go away. Whenever you have problems with testcase executon, look at well-placed Sleep statements as a possible solution to your problem. It shouldn't be that way, but it is !!!!
Speaking of Exists (), it takes an optional integer parameter, which represents the maximum time SilkTest should wait for the object to exist.
BOOLEAN b = w.Exists ()
BOOLEAN b = w.Exists (10)
The second example is better because it will wait UP TO 10 seconds, but no longer than it needs to. The first example will wait 10 seconds.
John W Green
[This message has been edited by John Green (edited 07-19-2000).]
Re: Sleep Function
The improper use of Sleep() - those that are just plopped in to the code "to make this run work" - can cause no end of grief in test suites for time sensitive applications. And it can seriously add to the long term maintenance effort when the application or its environment change.
As mentioned in John's example the Exists(value) method is far superior to a hard coded Sleep() that is followed by an action statement, particularly when the former is coded with a global constant to provides 'remote' single point control.
Hardcoded Sleep/action sequences can also dramatically lengthen regression test runs resulting in much wasted time where nothing useful happens.
In all cases where it is possible, a handshake method should be used instead of a time delay. This puts the greatest strain on the AUT and minimizes total test run time.
That said, I've found it occasionally useful to code a Sleep(0) - zero, that is - to force the Silk Agent to "take a break".
Another useful approach is to take control of the Exists() loop yourself by adding a fractional-second Sleep()increment with Error/Warning lines to indicate both a "expected window appeared in xx seconds" and a "window didn't appear within the alloted time". These are quite helpful in subsequent debug and performance analysis efforts. This code is best imbedded in the invoke or SetActive methods of a new class for the time-sensitive object.
Re: Sleep Function
Howabout using the WaitFor() and WaitForVital() functions in the download section?
The functions were written for QAP a long time ago by Dave Reed, but they still work nicely for me on Browser pages.