Exemple #1
0
        private static void WaitUntil(Func <bool> waitCondition, string exceptionMessage, int?timeoutInMilliseconds, int?sleepIntervalInMilliseconds)
        {
            var localTimeout       = timeoutInMilliseconds ?? 5000;
            var localSleepInterval = sleepIntervalInMilliseconds ?? 500;
            var wrappedWebDriver   = ServicesCollection.Current.Resolve <WindowsDriver <WindowsElement> >();
            var webDriverWait      = new WebDriverWait(new SystemClock(), wrappedWebDriver, TimeSpan.FromMilliseconds(localTimeout), TimeSpan.FromMilliseconds(localSleepInterval));

            webDriverWait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(StaleElementReferenceException));
            bool LocalCondition(IWebDriver s)
            {
                try
                {
                    return(waitCondition());
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            try
            {
                webDriverWait.Until(LocalCondition);
            }
            catch (WebDriverTimeoutException)
            {
                var elementPropertyValidateException = new ElementPropertyValidateException(exceptionMessage);
                ValidatedExceptionThrowedEvent?.Invoke(waitCondition, new ElementNotFulfillingValidateConditionEventArgs(elementPropertyValidateException));
                throw elementPropertyValidateException;
            }
        }
        internal static void WaitUntil <TDriver, TDriverElement>(Func <bool> waitCondition, string exceptionMessage, int?timeoutInMilliseconds, int?sleepIntervalInMilliseconds)
            where TDriver : AppiumDriver <TDriverElement>
            where TDriverElement : AppiumWebElement
        {
            var localTimeout       = timeoutInMilliseconds ?? ConfigurationService.GetSection <MobileSettings>().TimeoutSettings.ValidationsTimeout;
            var localSleepInterval = sleepIntervalInMilliseconds ?? ConfigurationService.GetSection <MobileSettings>().TimeoutSettings.SleepInterval;
            var wrappedWebDriver   = ServicesCollection.Current.Resolve <TDriver>();
            var webDriverWait      = new AppiumDriverWait <TDriver, TDriverElement>(wrappedWebDriver, new SystemClock(), TimeSpan.FromMilliseconds(localTimeout), TimeSpan.FromMilliseconds(localSleepInterval));

            webDriverWait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(StaleElementReferenceException));
            bool LocalCondition(IWebDriver s)
            {
                try
                {
                    return(waitCondition());
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            try
            {
                webDriverWait.Until(LocalCondition);
            }
            catch (WebDriverTimeoutException)
            {
                var elementPropertyValidateException = new ComponentPropertyValidateException(exceptionMessage);
                ValidatedExceptionThrowedEvent?.Invoke(waitCondition, new ComponentNotFulfillingValidateConditionEventArgs(elementPropertyValidateException));
                throw elementPropertyValidateException;
            }
        }