Exemple #1
0
        /// <summary>
        /// Gets the control that matches the conditions defined by the specified predicate expression.
        /// </summary>
        /// <param name="predicateExpression">The predicate expression to test each item.</param>
        /// <returns>The first item that matches the conditions of the specified predicate.</returns>
        public TItem this[Expression <Func <TItem, bool> > predicateExpression]
        {
            get
            {
                predicateExpression.CheckNotNull(nameof(predicateExpression));

                string itemName = UIComponentResolver.ResolveControlName <TItem, TOwner>(predicateExpression);

                return(GetItem(itemName, predicateExpression));
            }
        }
Exemple #2
0
        /// <summary>
        /// Searches for the item that matches the conditions defined by the specified predicate expression
        /// and returns the zero-based index of the first occurrence.
        /// </summary>
        /// <param name="predicateExpression">The predicate expression to test each item.</param>
        /// <returns>The zero-based index of the first occurrence of item, if found; otherwise, –1.</returns>
        public DataProvider <int, TOwner> IndexOf(Expression <Func <TItem, bool> > predicateExpression)
        {
            predicateExpression.CheckNotNull(nameof(predicateExpression));

            string itemName = UIComponentResolver.ResolveControlName <TItem, TOwner>(predicateExpression);

            return(Component.GetOrCreateDataProvider($"{ComponentPartName} index of \"{itemName}\" {ItemComponentTypeName}", () =>
            {
                return IndexOf(itemName, predicateExpression);
            }));
        }
        public static TOwner Contain <TControl, TOwner>(this IDataVerificationProvider <IEnumerable <TControl>, TOwner> should, Expression <Func <TControl, bool> > predicateExpression)
            where TControl : Control <TOwner>
            where TOwner : PageObject <TOwner>
        {
            predicateExpression.CheckNotNull(nameof(predicateExpression));
            var predicate = predicateExpression.Compile();

            return(should.Satisfy(
                       actual => actual != null && actual.Any(predicate),
                       $"contain \"{UIComponentResolver.ResolveControlName<TControl, TOwner>(predicateExpression)}\" {UIComponentResolver.ResolveControlTypeName<TControl>()}"));
        }
Exemple #4
0
        TOther IPageObject.GoTo <TOther>(TOther pageObject, GoOptions options)
        {
            bool isReturnedFromTemporary = TryResolvePreviousPageObjectNavigatedTemporarily(ref pageObject);

            pageObject = pageObject ?? ActivatorEx.CreateInstance <TOther>();

            if (!isReturnedFromTemporary)
            {
                if (!options.Temporarily)
                {
                    AtataContext.Current.CleanUpTemporarilyPreservedPageObjectList();
                }

                pageObject.NavigateOnInit = options.Navigate;

                if (options.Temporarily)
                {
                    pageObject.IsTemporarilyNavigated = options.Temporarily;
                    AtataContext.Current.TemporarilyPreservedPageObjectList.Add(this);
                }
            }

            ExecuteTriggers(TriggerEvents.DeInit);

            // TODO: Review that condition.
            if (!options.Temporarily)
            {
                UIComponentResolver.CleanUpPageObject(this);
            }

            if (!string.IsNullOrWhiteSpace(options.Url))
            {
                Go.ToUrl(options.Url);
            }

            if (!string.IsNullOrWhiteSpace(options.WindowName))
            {
                SwitchTo(options.WindowName);
            }

            if (isReturnedFromTemporary)
            {
                Log.Info("Go to {0}", pageObject.ComponentFullName);
            }
            else
            {
                pageObject.PreviousPageObject = this;
                pageObject.Init();
            }

            return(pageObject);
        }
Exemple #5
0
        /// <summary>
        /// Executes aggregate assertion for the component of the current page object using <see cref="AtataContext.AggregateAssert(Action, string)" /> method.
        /// </summary>
        /// <typeparam name="TComponent">The type of the component.</typeparam>
        /// <param name="componentSelector">The component selector.</param>
        /// <param name="action">The action to execute in scope of aggregate assertion.</param>
        /// <returns>The instance of this page object.</returns>
        public TOwner AggregateAssert <TComponent>(Func <TOwner, TComponent> componentSelector, Action <TComponent> action)
        {
            componentSelector.CheckNotNull(nameof(componentSelector));
            action.CheckNotNull(nameof(action));

            TComponent component = componentSelector((TOwner)this);

            string componentName = UIComponentResolver.ResolveComponentFullName <TOwner>(component) ?? ComponentFullName;

            AtataContext.Current.AggregateAssert(() => action(component), componentName);

            return((TOwner)this);
        }
Exemple #6
0
        protected PageObject()
        {
            NavigateOnInit = true;
            ScopeLocator   = new PlainScopeLocator(CreateScopeBy);

            Owner = (TOwner)this;

            Report = new Report <TOwner>((TOwner)this, Log);

            PageUri = new UriProvider <TOwner>(this, GetUri, "URI");

            UIComponentResolver.InitPageObject <TOwner>(this);
        }
Exemple #7
0
        /// <summary>
        /// Executes aggregate assertion for the component of the current page object using <see cref="AtataContext.AggregateAssert(Action, string)" /> method.
        /// </summary>
        /// <typeparam name="TComponent">The type of the component.</typeparam>
        /// <param name="componentSelector">The component selector.</param>
        /// <param name="action">The action to execute in scope of aggregate assertion.</param>
        /// /// <param name="assertionScopeName">
        /// Name of the scope being asserted.
        /// Is used to identify the assertion section in log.
        /// If it is <see langword="null"/>, component full name is used instead.
        /// </param>
        /// <returns>The instance of this page object.</returns>
        public TOwner AggregateAssert <TComponent>(Func <TOwner, TComponent> componentSelector, Action <TComponent> action, string assertionScopeName = null)
        {
            componentSelector.CheckNotNull(nameof(componentSelector));
            action.CheckNotNull(nameof(action));

            TComponent component = componentSelector((TOwner)this);

            assertionScopeName = assertionScopeName
                                 ?? UIComponentResolver.ResolveComponentFullName <TOwner>(component) ?? ComponentFullName;

            Context.AggregateAssert(() => action(component), assertionScopeName);

            return((TOwner)this);
        }
        public TControl Resolve <TControl>(string propertyName, Func <IEnumerable <Attribute> > additionalAttributesFactory = null)
            where TControl : Control <TOwner>
        {
            propertyName.CheckNotNullOrWhitespace(nameof(propertyName));

            TControl control = _component.Controls.OfType <TControl>().FirstOrDefault(x => x.Metadata.Name == propertyName);

            if (control != null)
            {
                return(control);
            }

            var additionalAttributes = additionalAttributesFactory?.Invoke()?.ToArray();

            return(UIComponentResolver.CreateControlForProperty <TControl, TOwner>(_component, propertyName, additionalAttributes));
        }
Exemple #9
0
        protected PageObject()
        {
            _context = AtataContext.Current
                       ?? throw new InvalidOperationException(
                                 $"Cannot instantiate {GetType().Name} because {nameof(AtataContext)}.{nameof(AtataContext.Current)} is null.");

            NavigateOnInit = true;
            ScopeLocator   = new PlainScopeLocator(CreateScopeBy);

            Owner = (TOwner)this;

            Report = new Report <TOwner>((TOwner)this, Log);

            PageUri = new UriProvider <TOwner>(this, GetUri, "URI");

            UIComponentResolver.InitPageObject <TOwner>(this);
        }
        public static TOwner ContainHavingContent <TControl, TOwner>(this IDataVerificationProvider <IEnumerable <TControl>, TOwner> should, TermMatch match, params string[] expected)
            where TControl : Control <TOwner>
            where TOwner : PageObject <TOwner>
        {
            expected.CheckNotNullOrEmpty(nameof(expected));

            return(should.Satisfy(
                       actual =>
            {
                if (actual == null)
                {
                    return false;
                }

                var actualValues = actual.Select(x => x.Content.Value).ToArray();
                return expected.All(expectedValue => actualValues.Any(actualValue => match.IsMatch(actualValue, expectedValue)));
            },
                       $"contain {UIComponentResolver.ResolveControlTypeName<TControl>()} having content that {match.ToString(TermCase.Lower)} {CollectionToString(expected)}"));
        }
Exemple #11
0
        /// <summary>
        /// Cleans up the test context.
        /// </summary>
        /// <param name="quitDriver">if set to <c>true</c> quits WebDriver.</param>
        public void CleanUp(bool quitDriver = true)
        {
            if (disposed)
            {
                return;
            }

            ExecuteCleanUpActions();

            TimeSpan cleanTestExecutionTime = DateTime.Now - CleanExecutionStartDateTime;

            Log.Start("Clean up test context");

            CleanUpTemporarilyPreservedPageObjectList();

            if (PageObject != null)
            {
                UIComponentResolver.CleanUpPageObject(PageObject);
            }

            if (quitDriver)
            {
                Driver.Quit();
            }

            Log.EndSection();

            TimeSpan testExecutionTime = DateTime.Now - TestStart;

            Log.InfoWithExecutionTimeInBrackets("Finished test", testExecutionTime);
            Log.InfoWithExecutionTime("Pure test execution time: ", cleanTestExecutionTime);

            Log = null;

            if (Current == this)
            {
                Current = null;
            }

            disposed = true;
        }
Exemple #12
0
        internal void Init()
        {
            ComponentName     = UIComponentResolver.ResolvePageObjectName <TOwner>();
            ComponentTypeName = UIComponentResolver.ResolvePageObjectTypeName <TOwner>();

            Log.Info($"Go to {ComponentFullName}");

            InitComponent();

            if (NavigateOnInit)
            {
                Navigate();
            }

            OnInit();

            ExecuteTriggers(TriggerEvents.Init);

            OnInitCompleted();

            OnVerify();
        }
Exemple #13
0
        internal void Init()
        {
            Log    = AtataContext.Current.Log;
            Driver = AtataContext.Current.Driver;

            ComponentName     = UIComponentResolver.ResolvePageObjectName <TOwner>();
            ComponentTypeName = UIComponentResolver.ResolvePageObjectTypeName <TOwner>();

            Log.Info("Go to {0}", ComponentFullName);

            OnInit();

            if (NavigateOnInit)
            {
                Navigate();
            }

            InitComponent();

            ExecuteTriggers(TriggerEvents.Init);

            OnVerify();
        }
 /// <inheritdoc/>
 public TControl Find <TControl>(string name, params Attribute[] attributes)
     where TControl : Control <TOwner>
 =>
 UIComponentResolver.CreateControl <TControl, TOwner>(this, name, attributes);
 [Obsolete("Don't use this method.")] // Obsolete since v1.9.0.
 public static string GetItemTypeName(Type type)
 {
     return(type.IsInheritedFromOrIs(typeof(Control <>))
         ? UIComponentResolver.ResolveControlTypeName(type)
         : "item");
 }
Exemple #16
0
 protected internal virtual void InitComponent()
 {
     UIComponentResolver.Resolve(this);
 }
 public ControlList <TControl, TOwner> FindAll <TControl>(params Attribute[] attributes)
     where TControl : Control <TOwner>
 =>
 FindAll <TControl>(
     $"{UIComponentResolver.ResolveControlTypeName<TControl>()} items",
     attributes);
 public ControlList <TControl, TOwner> FindAll <TControl>(string name, params Attribute[] attributes)
     where TControl : Control <TOwner>
 =>
 UIComponentResolver.CreateComponentPart <ControlList <TControl, TOwner>, TOwner>(this, name, attributes);
Exemple #19
0
        private ControlDefinitionAttribute ResolveItemDefinition()
        {
            ControlDefinitionAttribute definition = DeclaredAttributes?.OfType <ControlDefinitionAttribute>().FirstOrDefault();

            return(definition ?? UIComponentResolver.GetControlDefinition(typeof(TItem)));
        }
Exemple #20
0
 internal void CleanUpTemporarilyPreservedPageObjectList()
 {
     UIComponentResolver.CleanUpPageObjects(TemporarilyPreservedPageObjects);
     TemporarilyPreservedPageObjectList.Clear();
 }
 public TControl Create <TControl>(string name, params Attribute[] attributes)
     where TControl : Control <TOwner>
 {
     return(UIComponentResolver.CreateControl <TControl, TOwner>(component, name, attributes));
 }