예제 #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);
            }
        }
예제 #2
0
        private XPathComponentScopeLocateResult[] ResolveScopeLocateResult(ComponentScopeLocateResult result, IWebElement scopeSource, SearchOptions searchOptions)
        {
            result.CheckNotNull(nameof(result));

            if (result is MissingComponentScopeLocateResult missingResult)
            {
                return(new XPathComponentScopeLocateResult[0]);
            }

            if (result is XPathComponentScopeLocateResult xPathResult)
            {
                return new[] { xPathResult }
            }
            ;

            if (result is SequalComponentScopeLocateResult sequalResult)
            {
                ComponentScopeLocateOptions nextScopeLocateOptions = sequalResult.ScopeLocateOptions ?? scopeLocateOptions;

                if (sequalResult.ScopeSource != null)
                {
                    ComponentScopeLocateResult nextResult = sequalResult.Strategy.Find(sequalResult.ScopeSource, nextScopeLocateOptions, searchOptions);
                    return(ResolveScopeLocateResult(nextResult, sequalResult.ScopeSource, searchOptions));
                }
                else
                {
                    IWebElement[] nextScopeSources = scopeSource.GetAll(sequalResult.ScopeSourceBy.With(searchOptions)).ToArray();

                    SearchOptions nextSearchOptions = SearchOptions.SafelyAtOnce();

                    var results = nextScopeSources.
                                  Select(nextScopeSource => sequalResult.Strategy.Find(nextScopeSource, nextScopeLocateOptions, nextSearchOptions)).
                                  Select(nextResult => ResolveScopeLocateResult(nextResult, nextScopeSources[0], nextSearchOptions)).
                                  Where(xPathResults => xPathResults != null).
                                  SelectMany(xPathResults => xPathResults).
                                  ToArray();

                    if (results.Any())
                    {
                        return(results);
                    }
                    else if (searchOptions.IsSafely)
                    {
                        return(new XPathComponentScopeLocateResult[0]);
                    }
                    else
                    {
                        throw ExceptionFactory.CreateForNoSuchElement(by: sequalResult.ScopeSourceBy);
                    }
                }
            }

            throw new ArgumentException($"Unsupported {nameof(ComponentScopeLocateResult)} type: {result.GetType().FullName}", nameof(result));
        }
    }
예제 #3
0
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder(ComponentFullName);
            IWebElement   scope   = GetScopeElement(SearchOptions.SafelyAtOnce());

            if (scope != null)
            {
                builder.AppendLine().Append(scope.ToDetailedString());
            }

            return(builder.ToString());
        }
예제 #4
0
        protected override string GetParameterAsString(IWebElement element)
        {
            string elementId = element.GetAttribute("id");

            if (!string.IsNullOrEmpty(elementId))
            {
                IWebElement scope = component.ScopeSource.GetScopeElement(component, SearchOptions.SafelyAtOnce());

                IWebElement label = scope.Get(
                    By.XPath($".//label[@for='{elementId}']").
                    SafelyAtOnce());

                if (label != null)
                {
                    return(label.Text);
                }
            }

            return(element.Get(By.XPath("ancestor::label").AtOnce()).Text);
        }
예제 #5
0
        public override string GetXPathCondition(object parameter, TermOptions termOptions)
        {
            IWebElement scope = component.ScopeSource.GetScopeElement(component, SearchOptions.SafelyAtOnce());

            IWebElement label = scope.Get(
                By.XPath($".//label[{TermResolver.CreateXPathCondition(parameter, termOptions)}]").
                SafelyAtOnce().
                Label(TermResolver.ToDisplayString(parameter)));

            if (label != null)
            {
                string elementId = label.GetAttribute("for");

                if (!string.IsNullOrEmpty(elementId))
                {
                    return($"[@id='{elementId}']");
                }
            }

            return($"[ancestor::label[{TermResolver.CreateXPathCondition(parameter, termOptions)}]]");
        }
예제 #6
0
 protected virtual bool GetIsVisible()
 {
     return(GetScope(SearchOptions.SafelyAtOnce())?.Displayed ?? false);
 }
예제 #7
0
 protected virtual bool GetIsPresent()
 {
     return(GetScope(SearchOptions.SafelyAtOnce()) != null);
 }
예제 #8
0
        private XPathComponentScopeLocateResult[] ResolveScopeLocateResult(ComponentScopeLocateResult result, IWebElement scopeSource, SearchOptions searchOptions)
        {
            result.CheckNotNull(nameof(result));

            if (result is MissingComponentScopeLocateResult missingResult)
            {
                return(new XPathComponentScopeLocateResult[0]);
            }

            if (result is XPathComponentScopeLocateResult xPathResult)
            {
                return new[] { xPathResult }
            }
            ;

            if (result is SequalComponentScopeLocateResult sequalResult)
            {
                ComponentScopeLocateOptions nextScopeLocateOptions = sequalResult.ScopeLocateOptions ?? scopeLocateOptions;

                if (sequalResult.ScopeSources?.Count() == 1)
                {
                    return(ExecuteStrategyAndResolveResults(sequalResult.Strategy, sequalResult.ScopeSources.First(), nextScopeLocateOptions, searchOptions));
                }
                else
                {
                    IEnumerable <IWebElement> nextScopeSources = sequalResult.ScopeSourceBy != null
                        ? scopeSource.GetAll(sequalResult.ScopeSourceBy.With(searchOptions))
                        : sequalResult.ScopeSources;

                    SearchOptions nextSearchOptions = SearchOptions.SafelyAtOnce();

                    var results = nextScopeSources.
                                  Select(nextScopeSource => ExecuteStrategyAndResolveResults(sequalResult.Strategy, nextScopeSource, nextScopeLocateOptions, nextSearchOptions)).
                                  Where(xPathResults => xPathResults != null).
                                  SelectMany(xPathResults => xPathResults).
                                  ToArray();

                    if (results.Any())
                    {
                        return(results);
                    }
                    else if (searchOptions.IsSafely)
                    {
                        return(new XPathComponentScopeLocateResult[0]);
                    }
                    else
                    {
                        throw ExceptionFactory.CreateForNoSuchElement(
                                  new SearchFailureData
                        {
                            ElementName   = component.ComponentFullName,
                            By            = sequalResult.ScopeSourceBy,
                            SearchOptions = searchOptions,
                            SearchContext = scopeSource
                        });
                    }
                }
            }

            throw new ArgumentException($"Unsupported {nameof(ComponentScopeLocateResult)} type: {result.GetType().FullName}", nameof(result));
        }
예제 #9
0
        protected virtual bool GetIsVisibleInViewPort()
        {
            IWebElement element = GetScope(SearchOptions.SafelyAtOnce());

            return(element != null && element.Displayed && Script.Execute <bool>(IsInViewPortScript, element));
        }