How can I Implement a dynamic timeout in Teststack White? Ex. I am trying to locate an element after a postback event on web-browser. So there will be a delay before the element loads or the page may timeout. For both scenarios, a static timeout using Thread.Sleep works but how to implement a dynamic timeout interface that will continue execution if element is detected before timeout cap or will be timed-out when timeout cap is reached.
Thanks
You can implement extension method to get the element and put a wait condition inside.
public static T GetWithWait<T>(this Window window, SearchCriteria searchCriteria, int timeout = 30) where T : UIItem
{
T result = null;
for (int i = 0; i < timeout; i++)
{
result = window.Get<T>(searchCriteria);
if (result != null)
{
return result;
}
Thread.Sleep(TimeSpan.FromSeconds(1));
}
return result;
}
From Window object you can call this method with SearchCriteria you generally use to find the element.
If you want to use timeouts locally, take a look at
using (CoreAppXmlConfiguration.Instance.ApplyTemporarySetting(c => c.BusyTimeOut= 1500))
{
// your code here
}
Hope this helps.
Rik
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With