Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I Implement a dynamic timeout in Teststack White?

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

like image 605
Rahul Lodha Avatar asked May 16 '26 01:05

Rahul Lodha


2 Answers

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.

like image 81
llatinov Avatar answered May 19 '26 03:05

llatinov


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

like image 35
Rik Avatar answered May 19 '26 03:05

Rik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!