Пример #1
0
        public bool IsMissing(SearchOptions searchOptions = null, string xPathCondition = null)
        {
            searchOptions = ResolveSearchOptions(searchOptions);

            SearchOptions quickSearchOptions = SearchOptions.SafelyAtOnce();

            quickSearchOptions.Visibility = searchOptions.Visibility;

            bool isMissing = component.Driver.Try(searchOptions.Timeout, searchOptions.RetryInterval).Until(_ =>
            {
                XPathComponentScopeLocateResult[] xPathResults = GetScopeLocateResults(quickSearchOptions);
                if (xPathResults.Any())
                {
                    Dictionary <By, ISearchContext> byScopePairs = xPathResults.ToDictionary(x => x.CreateBy(xPathCondition), x => (ISearchContext)x.ScopeSource);
                    return(component.Driver.Try(TimeSpan.Zero).MissingAll(byScopePairs));
                }
                else
                {
                    return(true);
                }
            });

            if (!searchOptions.IsSafely && !isMissing)
            {
                throw ExceptionFactory.CreateForNotMissingElement(component.ComponentFullName);
            }
            else
            {
                return(isMissing);
            }
        }
        public bool Missing(By by)
        {
            SearchOptions options = by.GetSearchOptionsOrDefault();

            bool FindNoElement(T context)
            {
                return(options.Visibility == Visibility.Any
                    ? !context.FindElements(by).Any()
                    : !context.FindElements(by).Any(CreateVisibilityPredicate(options.Visibility)));
            }

            Stopwatch searchWatch = Stopwatch.StartNew();

            bool isMissing = Until(FindNoElement, options.ToRetryOptions());

            searchWatch.Stop();

            if (!options.IsSafely && !isMissing)
            {
                throw ExceptionFactory.CreateForNotMissingElement(
                          new SearchFailureData
                {
                    By            = by,
                    SearchTime    = searchWatch.Elapsed,
                    SearchOptions = options,
                    SearchContext = Context
                });
            }
            else
            {
                return(isMissing);
            }
        }
        public bool MissingAll(Dictionary <By, ISearchContext> byContextPairs)
        {
            byContextPairs.CheckNotNullOrEmpty(nameof(byContextPairs));

            Dictionary <By, SearchOptions> searchOptions = byContextPairs.Keys.ToDictionary(x => x, x => x.GetSearchOptionsOrDefault());

            List <By> leftBys = byContextPairs.Keys.ToList();

            bool FindNoElement(T context)
            {
                By[] currentByArray = leftBys.ToArray();

                foreach (By by in currentByArray)
                {
                    if (IsMissing(byContextPairs[by], by, searchOptions[by]))
                    {
                        leftBys.Remove(by);
                    }
                }

                if (!leftBys.Any())
                {
                    leftBys = byContextPairs.Keys.Except(currentByArray).Where(by => !IsMissing(byContextPairs[by], by, searchOptions[by])).ToList();
                    if (!leftBys.Any())
                    {
                        return(true);
                    }
                }

                return(false);
            }

            TimeSpan?maxTimeout       = searchOptions.Values.Where(x => x.IsTimeoutSet).Max(x => x.Timeout as TimeSpan?);
            TimeSpan?minRetryInterval = searchOptions.Values.Where(x => x.IsRetryIntervalSet).Min(x => x.RetryInterval as TimeSpan?);

            Stopwatch searchWatch = Stopwatch.StartNew();

            bool isMissing = Until(FindNoElement, maxTimeout, minRetryInterval);

            searchWatch.Stop();

            if (searchOptions.Values.Any(x => !x.IsSafely) && !isMissing)
            {
                By firstLeftBy = leftBys.FirstOrDefault();

                throw ExceptionFactory.CreateForNotMissingElement(
                          new SearchFailureData
                {
                    By            = firstLeftBy,
                    SearchTime    = searchWatch.Elapsed,
                    SearchOptions = firstLeftBy != null ? searchOptions[firstLeftBy] : null,
                    SearchContext = firstLeftBy != null ? byContextPairs[firstLeftBy] : null
                });
            }
            else
            {
                return(isMissing);
            }
        }
Пример #4
0
        public bool IsMissing(SearchOptions searchOptions = null, string xPathCondition = null)
        {
            searchOptions = searchOptions ?? new SearchOptions();

            bool isMissing = AtataContext.Current.Driver.Try(searchOptions.Timeout, searchOptions.RetryInterval).Until(_ =>
            {
                return(!predicate(searchOptions).Any());
            });

            if (!isMissing && !searchOptions.IsSafely)
            {
                throw ExceptionFactory.CreateForNotMissingElement();
            }
            else
            {
                return(isMissing);
            }
        }
Пример #5
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);
            }
        }
Пример #6
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);
            }
        }