예제 #1
0
        public static void Execute(Action <SearchOptions> action, SearchOptions options)
        {
            action.CheckNotNull(nameof(action));

            options = options ?? new SearchOptions();

            SearchOptions workingOptions = options.Clone();
            DateTime      startTime      = DateTime.Now;

            while (true)
            {
                try
                {
                    action(workingOptions);
                    return;
                }
                catch (StaleElementReferenceException exception)
                {
                    TimeSpan spentTime = DateTime.Now - startTime;

                    if (spentTime > options.Timeout)
                    {
                        throw ExceptionFactory.CreateForTimeout(spentTime, exception);
                    }
                    else
                    {
                        workingOptions.Timeout = options.Timeout - spentTime;
                    }
                }
            }
        }
        private StrategyScopeLocatorExecutionUnit CreateExecutionUnitForFinalFindAttribute(FindAttribute findAttribute, SearchOptions desiredSearchOptions)
        {
            object strategy = findAttribute.CreateStrategy();

            SearchOptions searchOptions = desiredSearchOptions.Clone();

            if (!desiredSearchOptions.IsVisibilitySet)
            {
                searchOptions.Visibility = findAttribute.Visibility;
            }

            if (!desiredSearchOptions.IsTimeoutSet)
            {
                searchOptions.Timeout = TimeSpan.FromSeconds(findAttribute.Timeout);
            }

            if (!desiredSearchOptions.IsRetryIntervalSet)
            {
                searchOptions.RetryInterval = TimeSpan.FromSeconds(findAttribute.RetryInterval);
            }

            ComponentScopeLocateOptions scopeLocateOptions = ComponentScopeLocateOptions.Create(_component, _component.Metadata, findAttribute);

            return(new StrategyScopeLocatorExecutionUnit(strategy, scopeLocateOptions, searchOptions));
        }
        public static TResult Execute <TResult>(Func <SearchOptions, TResult> action, SearchOptions options, Action onExceptionCallback = null)
        {
            action.CheckNotNull(nameof(action));

            options = options ?? new SearchOptions();

            SearchOptions workingOptions = options.Clone();
            DateTime      startTime      = DateTime.Now;

            while (true)
            {
                try
                {
                    return(action(workingOptions));
                }
                catch (StaleElementReferenceException exception)
                {
                    onExceptionCallback?.Invoke();

                    TimeSpan spentTime = DateTime.Now - startTime;

                    if (spentTime > options.Timeout)
                    {
                        throw ExceptionFactory.CreateForTimeout(spentTime, exception);
                    }
                    else
                    {
                        workingOptions.Timeout = options.Timeout - spentTime;
                    }
                }
            }
        }
예제 #4
0
        public bool IsMissing(SearchOptions searchOptions = null, string xPathCondition = null)
        {
            searchOptions = searchOptions ?? SearchOptions.Unsafely();

            SearchOptions searchOptionsForElementGet = searchOptions.Clone();
            searchOptionsForElementGet.IsSafely = true;

            IWebElement element = GetElement(searchOptionsForElementGet, xPathCondition);
            if (element != null && !searchOptions.IsSafely)
                throw ExceptionFactory.CreateForNotMissingElement();
            else
                return element == null;
        }
예제 #5
0
        private StrategyScopeLocatorExecutionUnit CreateExecutionUnitForFinalFindAttribute(FindAttribute findAttribute, SearchOptions desiredSearchOptions)
        {
            object strategy = findAttribute.CreateStrategy();

            SearchOptions searchOptions = desiredSearchOptions.Clone();

            // TODO: Set Timeout and RetryInterval too.
            if (!desiredSearchOptions.IsVisibilitySet)
            {
                searchOptions.Visibility = findAttribute.Visibility;
            }

            ComponentScopeLocateOptions scopeLocateOptions = ComponentScopeLocateOptions.Create(component, component.Metadata, findAttribute);

            return(new StrategyScopeLocatorExecutionUnit(strategy, scopeLocateOptions, searchOptions));
        }
예제 #6
0
        public bool IsMissing(SearchOptions searchOptions = null, string xPathCondition = null)
        {
            searchOptions = searchOptions ?? new SearchOptions();

            SearchOptions searchOptionsForElementGet = searchOptions.Clone();

            searchOptionsForElementGet.IsSafely = true;

            IWebElement element = GetElement(searchOptionsForElementGet, xPathCondition);

            if (element != null && !searchOptions.IsSafely)
            {
                throw ExceptionFactory.CreateForNotMissingElement();
            }
            else
            {
                return(element == null);
            }
        }
예제 #7
0
        public bool IsMissing(SearchOptions searchOptions = null, string xPathCondition = null)
        {
            searchOptions = searchOptions ?? new SearchOptions();

            SearchOptions quickSearchOptions = searchOptions.Clone();

            quickSearchOptions.IsSafely = true;
            quickSearchOptions.Timeout  = TimeSpan.Zero;

            var driver = AtataContext.Current.Driver;
            StrategyScopeLocatorExecutionData executionData = _executionDataCollector.Get(quickSearchOptions);

            bool isMissing = driver.Try(searchOptions.Timeout, searchOptions.RetryInterval).Until(_ =>
            {
                XPathComponentScopeFindResult[] xPathResults = _executor.Execute(executionData);

                if (xPathResults.Any())
                {
                    Dictionary <By, ISearchContext> byScopePairs = xPathResults.ToDictionary(x => x.CreateBy(xPathCondition), x => x.ScopeSource);
                    return(driver.Try(TimeSpan.Zero).MissingAll(byScopePairs));
                }
                else
                {
                    return(true);
                }
            });

            if (!searchOptions.IsSafely && !isMissing)
            {
                throw ExceptionFactory.CreateForNotMissingElement(
                          new SearchFailureData
                {
                    ElementName   = executionData.Component.ComponentFullName,
                    SearchOptions = searchOptions
                });
            }
            else
            {
                return(isMissing);
            }
        }