Thursday 4 August 2016

TryFind vs WaitForControl(Ready/Exist)


TryFind() changed the test execution. The reason is that TryFind() would return true/false immediately when pages are still loading and its returned value would heavily depend on the responsiveness of the web server, so some tests would be fixed by simply replacing it with WaitForControlExist() which would block the current thread until timeout specified by default PlaybackSettings.WaitForReadyTimeout.

However prefer specifying timeout setting explicitly by calling WaitForControlReady(int millisecondsTimeout) or WaitForControlExist(int millisecondsTimeout). Somebody might accustomed with Playback.Wait(int thinkTimeMilliseconds) or Thread. Sleep(int millisecondsTimeout), but they might wait unnecessarily long. 

In addition, if combined with Assertion as be;pw:
Assert.IsTrue(someElement.WaitForControlReady(60*1000)); //Wait for 1 min
Unexpected delay could be highlighted immediately.
There are multiple WaitForControl() functions defined with UITestControl, some of them could be very helpful but are usually neglected, for example:
  • WaitForControlCondition(Predicate<UITestControl> conditionEvaluator, int millisecondsTimeout), combined with LINQ, provides a very powerful means to evaluate any status of the target control.
  • WaitForControlPropertyEqual(string propertyName, object propertyValue, int millisecondsTimeout) enables tester to monitor changes of any attribute of the control effectively.
  • bool WaitForControlNotExist(int millisecondsTimeout), combined with Assert.IsTrue(), could be used to evaluate operations have successfully caused the page changing to another state.
  • bool WaitForControlExist(int millisecondsTimeout) and bool WaitForControlReady(int millisecondsTimeout) should be used from time to time before performing solid operations like clicking, selecting or typing. Usually, the former is good enough especially when such operations would be carried out only when the browser/control is ready. But they might return different values for a specific control: usually WaitForControlExist() would return true when the target control is displayed, but in some of my projects, WaitForControlReady() would return true several minutes after WaitForControlExist() returning true.

No comments:

Post a Comment