Пример #1
0
        private static string ResolveControlName(UIComponentMetadata metadata, FindAttribute findAttribute)
        {
            NameAttribute nameAttribute = metadata.Get <NameAttribute>(AttributeLevels.Declared);

            if (nameAttribute != null && !string.IsNullOrWhiteSpace(nameAttribute.Value))
            {
                return(nameAttribute.Value);
            }

            FindByLabelAttribute findByLabelAttribute = findAttribute as FindByLabelAttribute;

            if (findByLabelAttribute != null)
            {
                if (findByLabelAttribute.Values != null && findByLabelAttribute.Values.Any())
                {
                    return(string.Join("/", findByLabelAttribute.Values));
                }
                else
                {
                    TermAttribute termAttribute = metadata.Get <TermAttribute>(AttributeLevels.Declared);
                    if (termAttribute != null && termAttribute.Values != null && termAttribute.Values.Any())
                    {
                        return(string.Join("/", termAttribute.Values));
                    }
                }
            }

            return(metadata.ComponentDefinitonAttribute.
                   NormalizeNameIgnoringEnding(metadata.Name).
                   ToString(TermCase.Title));
        }
Пример #2
0
        private static string ResolveControlName(UIComponentMetadata metadata, FindAttribute findAttribute)
        {
            NameAttribute nameAttribute = metadata.Get <NameAttribute>(x => x.At(AttributeLevels.Declared));

            if (!string.IsNullOrWhiteSpace(nameAttribute?.Value))
            {
                return(nameAttribute.Value);
            }

            if (findAttribute is FindByLabelAttribute findByLabelAttribute && findByLabelAttribute.Match == TermMatch.Equals)
            {
                if (findByLabelAttribute.Values?.Any() ?? false)
                {
                    return(string.Join("/", findByLabelAttribute.Values));
                }
                else
                {
                    TermAttribute termAttribute = metadata.Get <TermAttribute>(x => x.At(AttributeLevels.Declared));
                    if (termAttribute?.Values?.Any() ?? false)
                    {
                        return(string.Join("/", termAttribute.Values));
                    }
                }
            }

            return(metadata.ComponentDefinitionAttribute.
                   NormalizeNameIgnoringEnding(metadata.Name).
                   ToString(TermCase.Title));
        }
Пример #3
0
        private bool ShouldUseParentScope()
        {
            if (!(ScopeLocator is StrategyScopeLocator))
            {
                return(false);
            }

            FindAttribute findAttribute = Metadata.ResolveFindAttribute();

            return(findAttribute is UseParentScopeAttribute);
        }
Пример #4
0
        private static string GetComponentNameFromMetadata(UIComponentMetadata metadata)
        {
            if (metadata.Name is null)
            {
                FindAttribute findAttribute = metadata.ResolveFindAttribute();

                return(findAttribute.BuildComponentName());
            }
            else
            {
                return(metadata.ComponentDefinitionAttribute.
                       NormalizeNameIgnoringEnding(metadata.Name).
                       ToString(TermCase.Title));
            }
        }
Пример #5
0
        private static string GetControlNameFromFindAttribute(UIComponentMetadata metadata)
        {
            FindAttribute findAttribute = metadata.ResolveFindAttribute();

            if (findAttribute is FindByLabelAttribute findByLabelAttribute && findByLabelAttribute.Match == TermMatch.Equals)
            {
                string[] terms = findByLabelAttribute.Values;

                if (terms?.Any() ?? false)
                {
                    return(string.Join("/", terms));
                }
            }

            return(null);
        }
Пример #6
0
        private static void InitComponent <TOwner>(UIComponent <TOwner> component, UIComponent <TOwner> parentComponent, UIComponentMetadata metadata)
            where TOwner : PageObject <TOwner>
        {
            component.Owner  = parentComponent.Owner ?? (TOwner)parentComponent;
            component.Parent = parentComponent;

            FindAttribute findAttribute = GetPropertyFindAttribute(metadata);

            findAttribute.Properties.Metadata = metadata;

            InitComponentLocator(component, metadata, findAttribute);
            component.ComponentName     = ResolveControlName(metadata, findAttribute);
            component.ComponentTypeName = ResolveControlTypeName(metadata);
            component.CacheScopeElement = false;
            InitControlTriggers(component, metadata);

            ApplyMetadata(component, metadata);
        }
Пример #7
0
        [Obsolete("This method is not used anymore, no sense to invoke or override it.")] // Obsolete since v1.5.0.
        protected virtual By CreateItemBy()
        {
            FindAttribute itemFindAttribute = ResolveItemFindAttribute();

            itemFindAttribute.Properties.Metadata = Metadata;

            string outerXPath = itemFindAttribute.OuterXPath ?? ".//";

            By by = By.XPath($"{outerXPath}{ItemDefinition.ScopeXPath}").OfKind(ItemComponentTypeName);

            // TODO: Review/remake this Visibility processing.
            if (itemFindAttribute.Visibility == Visibility.Any)
            {
                by = by.OfAnyVisibility();
            }
            else if (itemFindAttribute.Visibility == Visibility.Hidden)
            {
                by = by.Hidden();
            }

            return(by);
        }
        public StrategyScopeLocatorExecutionData Get(SearchOptions searchOptions)
        {
            searchOptions = searchOptions ?? new SearchOptions();

            FindAttribute[] layerFindAttributes = _component.Metadata.ResolveLayerFindAttributes().ToArray();

            FindAttribute findAttribute = _component.Metadata.ResolveFindAttribute();

            var layerExecutionUnits = layerFindAttributes
                                      .Select(x => CreateExecutionUnitForLayerFindAttribute(x, searchOptions))
                                      .ToArray();

            var finalExecutionUnit = CreateExecutionUnitForFinalFindAttribute(findAttribute, searchOptions);

            ScopeSource scopeSource = layerFindAttributes.Any() && layerFindAttributes[0].Properties.Contains(nameof(FindAttribute.ScopeSource))
                ? layerFindAttributes[0].ScopeSource
                : findAttribute.ScopeSource;

            PostProcessOuterXPath(layerExecutionUnits, finalExecutionUnit);

            return(new StrategyScopeLocatorExecutionData(_component, scopeSource, searchOptions.IsSafely, layerExecutionUnits, finalExecutionUnit));
        }
Пример #9
0
        private static FindAttribute GetPropertyFindAttribute(UIComponentMetadata metadata)
        {
            FindAttribute findAttribute = metadata.Get <FindAttribute>(x => x.At(AttributeLevels.Declared));

            if (findAttribute != null)
            {
                return(findAttribute);
            }
            else
            {
                Type controlType         = metadata.ComponentType;
                Type parentComponentType = metadata.ParentComponentType;

                ControlFindingAttribute controlFindingAttribute =
                    GetNearestControlFindingAttribute(controlType, parentComponentType, metadata.ParentComponentAttributes) ??
                    GetNearestControlFindingAttribute(controlType, parentComponentType, metadata.AssemblyAttributes) ??
                    GetNearestDefaultControlFindingAttribute(parentComponentType, metadata.ComponentAttributes);

                return(controlFindingAttribute != null
                    ? controlFindingAttribute.CreateFindAttribute()
                    : GetDefaultFindAttribute(metadata));
            }
        }
Пример #10
0
        private static void InitComponentLocator(UIComponent component, UIComponentMetadata metadata, FindAttribute findAttribute)
        {
            ComponentScopeLocateOptions   locateOptions = CreateScopeLocateOptions(metadata, findAttribute);
            IComponentScopeLocateStrategy strategy      = findAttribute.CreateStrategy(metadata);

            component.ScopeSource = findAttribute.ScopeSource;

            // TODO: Remove this condition when IItemsControl will be removed.
#pragma warning disable CS0618
            if (component is IItemsControl itemsControl)
#pragma warning restore CS0618
            {
                IFindItemAttribute       findItemAttribute       = GetPropertyFindItemAttribute(metadata);
                IItemElementFindStrategy itemElementFindStrategy = findItemAttribute.CreateStrategy(component, metadata);
                itemsControl.Apply(itemElementFindStrategy);
            }

            component.ScopeLocator = new StrategyScopeLocator(component, strategy, locateOptions);
        }
Пример #11
0
        private static void InitComponentLocator(UIComponent component, UIComponentMetadata metadata, FindAttribute findAttribute)
        {
            ComponentScopeLocateOptions   locateOptions = CreateScopeLocateOptions(metadata, findAttribute);
            IComponentScopeLocateStrategy strategy      = findAttribute.CreateStrategy(metadata);

            component.ScopeSource = findAttribute.ScopeSource;

            if (component is IItemsControl itemsControl)
            {
                IFindItemAttribute       findItemAttribute       = GetPropertyFindItemAttribute(metadata);
                IItemElementFindStrategy itemElementFindStrategy = findItemAttribute.CreateStrategy(component, metadata);
                itemsControl.Apply(itemElementFindStrategy);
            }

            component.ScopeLocator = new StrategyScopeLocator(component, strategy, locateOptions);
        }
Пример #12
0
        private static ComponentScopeLocateOptions CreateScopeLocateOptions(UIComponentMetadata metadata, FindAttribute findAttribute)
        {
            ControlDefinitionAttribute definition = metadata.ComponentDefinitonAttribute as ControlDefinitionAttribute;

            int index = findAttribute.Index;

            ComponentScopeLocateOptions options = new ComponentScopeLocateOptions
            {
                Metadata     = metadata,
                ElementXPath = definition != null ? definition.ScopeXPath : "*",
                Index        = index >= 0 ? (int?)index : null,
                Visibility   = findAttribute.Visibility
            };

            ITermFindAttribute      termFindAttribute      = findAttribute as ITermFindAttribute;
            ITermMatchFindAttribute termMatchFindAttribute = findAttribute as ITermMatchFindAttribute;

            if (termFindAttribute != null)
            {
                options.Terms = termFindAttribute.GetTerms(metadata);
            }

            if (termMatchFindAttribute != null)
            {
                options.Match = termMatchFindAttribute.GetTermMatch(metadata);
            }

            return(options);
        }
Пример #13
0
 private void InitItemFindAttribute(FindAttribute findAttribute)
 {
     findAttribute.Visibility  = ItemFindAttribute.Visibility;
     findAttribute.ScopeSource = ItemFindAttribute.ScopeSource;
     findAttribute.OuterXPath  = ItemFindAttribute.OuterXPath;
 }
Пример #14
0
        private StrategyScopeLocatorLayerExecutionUnit CreateExecutionUnitForLayerFindAttribute(FindAttribute findAttribute, SearchOptions desiredSearchOptions)
        {
            object strategy = findAttribute.CreateStrategy();

            // TODO: Set Timeout and RetryInterval too.
            SearchOptions searchOptions = new SearchOptions
            {
                IsSafely   = desiredSearchOptions.IsSafely,
                Visibility = findAttribute.Visibility
            };

            ComponentScopeLocateOptions scopeLocateOptions   = ComponentScopeLocateOptions.Create(component, findAttribute.Properties.Metadata, findAttribute);
            ILayerScopeContextResolver  scopeContextResolver = LayerScopeContextResolverFactory.Create(findAttribute.As);

            return(new StrategyScopeLocatorLayerExecutionUnit(strategy, scopeLocateOptions, searchOptions, scopeContextResolver));
        }
Пример #15
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));
        }
Пример #16
0
 private static string ResolveControlName(UIComponentMetadata metadata, FindAttribute findAttribute)
 {
     return(GetControlNameFromNameAttribute(metadata)
            ?? GetControlNameFromFindAttribute(metadata, findAttribute)
            ?? GetComponentNameFromMetadata(metadata));
 }
Пример #17
0
        private static string GetControlNameFromFindAttribute(UIComponentMetadata metadata, FindAttribute findAttribute)
        {
            if (findAttribute is FindByLabelAttribute findByLabelAttribute && findByLabelAttribute.Match == TermMatch.Equals)
            {
                if (findByLabelAttribute.Values?.Any() ?? false)
                {
                    return(string.Join("/", findByLabelAttribute.Values));
                }
                else
                {
                    TermAttribute termAttribute = metadata.Get <TermAttribute>(x => x.At(AttributeLevels.Declared));
                    if (termAttribute?.Values?.Any() ?? false)
                    {
                        return(string.Join("/", termAttribute.Values));
                    }
                }
            }

            return(null);
        }
        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));
        }
Пример #19
0
        private static ComponentScopeLocateOptions CreateScopeLocateOptions(UIComponentMetadata metadata, FindAttribute findAttribute)
        {
            ControlDefinitionAttribute definition = metadata.ComponentDefinitionAttribute as ControlDefinitionAttribute;

            int index = findAttribute.Index;

            ComponentScopeLocateOptions options = new ComponentScopeLocateOptions
            {
                Metadata     = metadata,
                ElementXPath = definition?.ScopeXPath ?? ScopeDefinitionAttribute.DefaultScopeXPath,
                Index        = index >= 0 ? (int?)index : null,
                Visibility   = findAttribute.Visibility,
                OuterXPath   = findAttribute.OuterXPath
            };

            if (findAttribute is ITermFindAttribute termFindAttribute)
            {
                options.Terms = termFindAttribute.GetTerms(metadata);
            }

            if (findAttribute is ITermMatchFindAttribute termMatchFindAttribute)
            {
                options.Match = termMatchFindAttribute.GetTermMatch(metadata);
            }

            return(options);
        }
        private StrategyScopeLocatorLayerExecutionUnit CreateExecutionUnitForLayerFindAttribute(FindAttribute findAttribute, SearchOptions desiredSearchOptions)
        {
            object strategy = findAttribute.CreateStrategy();

            SearchOptions searchOptions = new SearchOptions
            {
                IsSafely      = desiredSearchOptions.IsSafely,
                Visibility    = findAttribute.Visibility,
                Timeout       = TimeSpan.FromSeconds(findAttribute.Timeout),
                RetryInterval = TimeSpan.FromSeconds(findAttribute.RetryInterval)
            };

            ComponentScopeLocateOptions scopeLocateOptions   = ComponentScopeLocateOptions.Create(_component, findAttribute.Properties.Metadata, findAttribute);
            ILayerScopeContextResolver  scopeContextResolver = LayerScopeContextResolverFactory.Create(findAttribute.As);

            return(new StrategyScopeLocatorLayerExecutionUnit(strategy, scopeLocateOptions, searchOptions, scopeContextResolver));
        }