Good Things Come to Him Who Waits (Instead of Sleeping)

I avoid putting sleeps into my test code. It’s never certain how much time is needed for the hoped-for state to be reached. And the sleep time has to be the longest time believed necessary, even if a much shorter time often would have served.

Waits are better, but I’ve had trouble with some CUIT wait methods, which sometimes seem not to have the desired effect: a search succeeds, but accessing the found control causes an exception.

Recently, I’ve added to the search code these wait method calls:

String state = UITestControl.PropertyNames.State;
ControlStates nvail = ControlStates.Unavailable;
ControlStates nvisi = ControlStates.Invisible;
foundControl.WaitForControlPropertyNotEqual(state, nvail);
foundControl.WaitForControlPropertyNotEqual(state, nvisi);

So far, they seem to be effective; I have not had a false search failure recently.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s